void LinearBalanceFeedback::loadFromFile(FILE* f){ if (f == NULL) throwError("File pointer is NULL - cannot read gain coefficients!!"); //have a temporary buffer used to read the file line by line... char buffer[200]; //this is where it happens. while (!feof(f)){ //get a line from the file... fgets(buffer, 200, f); if (strlen(buffer)>195) throwError("The input file contains a line that is longer than ~200 characters - not allowed"); char *line = lTrim(buffer); int lineType = getConLineType(line); switch (lineType) { case CON_FEEDBACK_END: //we're done... return; break; case CON_COMMENT: break; case CON_CV: if (sscanf(line, "%lf", &this->cv)!=1) throwError("A cv value must be specified!"); break; case CON_CD: if (sscanf(line, "%lf", &this->cd)!=1) throwError("A cd value must be specified!"); break; case CON_D_MIN: if (sscanf(line, "%lf", &this->dMin)!=1) throwError("A dMin value must be specified!"); break; case CON_D_MAX: if (sscanf(line, "%lf", &this->dMax)!=1) throwError("A dMax value must be specified!"); break; case CON_V_MIN: if (sscanf(line, "%lf", &this->vMin)!=1) throwError("A vMin value must be specified!"); break; case CON_V_MAX: if (sscanf(line, "%lf", &this->vMax)!=1) throwError("A vMax value must be specified!"); break; case CON_FEEDBACK_PROJECTION_AXIS: if (sscanf(line, "%lf %lf %lf", &this->feedbackProjectionAxis.x, &this->feedbackProjectionAxis.y, &this->feedbackProjectionAxis.z)!=3) throwError("The axis for a trajectory is specified by three parameters!"); this->feedbackProjectionAxis.toUnit(); break; case CON_NOT_IMPORTANT: tprintf("Ignoring input line: \'%s\'\n", line); break; default: throwError("Incorrect SIMBICON input file: \'%s\' - unexpected line.", buffer); } } throwError("Incorrect SIMBICON input file: No \'/jointTrajectory\' found ", buffer); }
char* readLine(FILE* file) { char str[255]; /* TODO: replace all scanf code */ fscanf(file, "%s", str); return lTrim(str, ' '); }
/** This method reads a list of rigid bodies from the specified file. */ void AbstractRBEngine::loadRBsFromFile(char* fName){ if (fName == NULL) throwError("NULL file name provided."); FILE *f = fopen(fName, "r"); if (f == NULL) throwError("Could not open file: %s", fName); //have a temporary buffer used to read the file line by line... char buffer[200]; RigidBody* newBody = NULL; ArticulatedFigure* newFigure = NULL; //this is where it happens. while (!feof(f)){ //get a line from the file... fgets(buffer, 200, f); if (strlen(buffer)>195) throwError("The input file contains a line that is longer than ~200 characters - not allowed"); char *line = lTrim(buffer); int lineType = getRBLineType(line); switch (lineType) { case RB_RB: //create a new rigid body and have it load its own info... newBody = new RigidBody(); newBody->loadFromFile(f); objects.push_back(newBody); break; case RB_ARB: //create a new articulated rigid body and have it load its own info... newBody = new ArticulatedRigidBody(); newBody->loadFromFile(f); objects.push_back(newBody); //remember it as an articulated rigid body to be able to link it with other ABs later on ABs.push_back((ArticulatedRigidBody*)newBody); break; case RB_ARTICULATED_FIGURE: //we have an articulated figure to worry about... newFigure = new ArticulatedFigure(); AFs.push_back(newFigure); newFigure->loadFromFile(f, this); newFigure->addJointsToList(&jts); break; case RB_NOT_IMPORTANT: if (strlen(line)!=0 && line[0] != '#') tprintf("Ignoring input line: \'%s\'\n", line); break; default: throwError("Incorrect rigid body input file: \'%s\' - unexpected line.", buffer); } } //now we'll make sure that the joint constraints are satisfied for (uint i=0;i<AFs.size();i++) AFs[i]->fixJointConstraints(); //and now make sure that each rigid body's toWorld transformation is updated // for (uint i=0;i<objects.size();i++){ // objects[i]->updateToWorldTransformation(); // } }
void CommonTestsSuite::test_ltrim() { string str; str = ""; lTrim(str); TS_ASSERT(str == ""); str = " "; lTrim(str); TS_ASSERT(str == ""); str = " b"; lTrim(str); TS_ASSERT(str == "b"); str = " bb"; lTrim(str); TS_ASSERT(str == "bb"); str = " bb "; lTrim(str); TS_ASSERT(str == "bb "); str = " bb b"; lTrim(str); TS_ASSERT(str == "bb b"); str = " bb b "; lTrim(str); TS_ASSERT(str == "bb b "); }
char* trimSpace(char String[]) { rTrim(String); lTrim(String); /* Trim Space all */ char *ptr = strstr(String, " "); while (ptr != NULL) { strcpy (ptr, ptr+1); ptr = strstr(String, " "); } return String; }
/** This method is used to read a trajectory from a file */ void Trajectory::readTrajectory(FILE* f){ if (f == NULL) throwError("File pointer is NULL - cannot read gain coefficients!!"); //have a temporary buffer used to read the file line by line... char buffer[200]; TrajectoryComponent* newComponent; //this is where it happens. while (!feof(f)){ //get a line from the file... fgets(buffer, 200, f); if (strlen(buffer)>195) throwError("The input file contains a line that is longer than ~200 characters - not allowed"); char *line = lTrim(buffer); int lineType = getConLineType(line); switch (lineType) { case CON_STRENGTH_TRAJECTORY_START: //read in the base trajectory if( strengthTraj != NULL ) throwError( "Two strength trajectory, this is illegal!" ); strengthTraj = new Trajectory1D(); SimBiConState::readTrajectory1D(f, *strengthTraj, CON_STRENGTH_TRAJECTORY_END ); break; case CON_TRAJECTORY_END: //we're done... return; break; case CON_CHAR_FRAME_RELATIVE: relToCharFrame = true; break; case CON_COMMENT: break; case CON_TRAJ_COMPONENT: //read in the base trajectory newComponent = new TrajectoryComponent(); newComponent->readTrajectoryComponent(f); components.push_back(newComponent); break; case CON_NOT_IMPORTANT: tprintf("Ignoring input line: \'%s\'\n", line); break; default: throwError("Incorrect SIMBICON input file: \'%s\' - unexpected line.", buffer); } } throwError("Incorrect SIMBICON input file: No \'/trajectory\' found ", buffer); }
/** This method is used to read the knots of a strength trajectory from the file, where they are specified one (knot) on a line */ void SimBiConState::readTrajectory1D(FILE* f, Trajectory1D& result, int endingLineType ){ if (f == NULL) throwError("File pointer is NULL - cannot read gain coefficients!!"); //have a temporary buffer used to read the file line by line... char buffer[200]; double temp1, temp2; //this is where it happens. while (!feof(f)){ //get a line from the file... fgets(buffer, 200, f); if (strlen(buffer)>195) throwError("The input file contains a line that is longer than ~200 characters - not allowed"); char *line = lTrim(buffer); int lineType = getConLineType(line); if( lineType == endingLineType ) //we're done... return; switch (lineType) { case CON_COMMENT: break; case CON_NOT_IMPORTANT: //we expect pairs of numbers, one pair on each row, so see if we have a valid pair if (sscanf(line, "%lf %lf", &temp1, &temp2) == 2){ result.addKnot(temp1, temp2); }else tprintf("Ignoring input line: \'%s\'\n", line); break; default: throwError("Incorrect SIMBICON input file: \'%s\' - unexpected line.", buffer); } } throwError("Incorrect SIMBICON input file: Trajectory not closed ", buffer); }
/** This method is used to read the state parameters from a file */ void SimBiConState::readState(FILE* f, int offset){ if (f == NULL) throwError("File pointer is NULL - cannot read gain coefficients!!"); //have a temporary buffer used to read the file line by line... char buffer[200]; Trajectory* tempTraj; //this is where it happens. while (!feof(f)){ //get a line from the file... fgets(buffer, 200, f); if (strlen(buffer)>195) throwError("The input file contains a line that is longer than ~200 characters - not allowed"); char *line = lTrim(buffer); int lineType = getConLineType(line); switch (lineType) { case CON_STATE_END: //we're done... return; break; case CON_NEXT_STATE: if (sscanf(line, "%d", &this->nextStateIndex) != 1) throwError("An index must be specified when using the \'nextState\' keyword"); this->nextStateIndex += offset; break; case CON_STATE_DESCRIPTION: strcpy(this->description, trim(line)); break; case CON_STATE_TIME: if (sscanf(line, "%lf", &stateTime)!=1) throwError("The time that is expected to be spent in this state needs to be provided."); break; case CON_STATE_STANCE: reverseStance = false; keepStance = false; if (strncmp(trim(line), "left",4) == 0) stateStance = LEFT_STANCE; else if (strncmp(trim(line), "right", 5) == 0) stateStance = RIGHT_STANCE; else if (strncmp(trim(line), "reverse", 7) == 0) reverseStance = true; else if (strncmp(trim(line), "same", 4) == 0) keepStance = true; else throwError("When using the \'stateStance\' keyword, \'left\', \'right\' or \'reverse\' must be specified."); break; case CON_TRANSITION_ON: transitionOnFootContact = false; if (strncmp(trim(line), "footDown", 8) == 0) transitionOnFootContact = true; else if (strncmp(trim(line), "timeUp", 6) == 0) //nothn' to do, since this is the default ; else throwError("When using the \'transitionOn\' keyword, \'footDown\' or \'timeUp\' must be specified."); break; case CON_TRAJECTORY_START: //create a new trajectory, and read its information from the file tempTraj = new Trajectory(); strcpy(tempTraj->jName, trim(line)); tempTraj->readTrajectory(f); this->sTraj.push_back(tempTraj); break; case CON_D_TRAJX_START: if( dTrajX != NULL ) throwError( "Two dTrajX trajectory, this is illegal!" ); dTrajX = new Trajectory1D(); readTrajectory1D( f, *dTrajX, CON_D_TRAJX_END ); break; case CON_D_TRAJZ_START: if( dTrajZ != NULL ) throwError( "Two dTrajZ trajectory, this is illegal!" ); dTrajZ = new Trajectory1D(); readTrajectory1D( f, *dTrajZ, CON_D_TRAJZ_END ); break; case CON_V_TRAJX_START: if( vTrajX != NULL ) throwError( "Two vTrajX trajectory, this is illegal!" ); vTrajX = new Trajectory1D(); readTrajectory1D( f, *vTrajX, CON_V_TRAJX_END ); break; case CON_V_TRAJZ_START: if( vTrajZ != NULL ) throwError( "Two vTrajZ trajectory, this is illegal!" ); vTrajZ = new Trajectory1D(); readTrajectory1D( f, *vTrajZ, CON_V_TRAJZ_END ); break; case CON_COMMENT: break; case CON_NOT_IMPORTANT: tprintf("Ignoring input line: \'%s\'\n", line); break; default: throwError("Incorrect SIMBICON input file: \'%s\' - unexpected line.", buffer); } } throwError("Incorrect SIMBICON input file: No \'/State\' found", buffer); }
/** This method is used to read a trajectory from a file */ void TrajectoryComponent::readTrajectoryComponent(FILE* f){ if (f == NULL) throwError("File pointer is NULL - cannot read gain coefficients!!"); //have a temporary buffer used to read the file line by line... char buffer[200]; char tmpString[200]; //this is where it happens. while (!feof(f)){ //get a line from the file... fgets(buffer, 200, f); if (strlen(buffer)>195) throwError("The input file contains a line that is longer than ~200 characters - not allowed"); char *line = lTrim(buffer); int lineType = getConLineType(line); switch (lineType) { case CON_TRAJ_COMPONENT_END: //we're done... return; break; case CON_COMMENT: break; case CON_ROTATION_AXIS: if (sscanf(line, "%lf %lf %lf", &this->rotationAxis.x, &this->rotationAxis.y, &this->rotationAxis.z)!=3) throwError("The axis for a trajectory is specified by three parameters!"); this->rotationAxis.toUnit(); break; case CON_FEEDBACK_START: //read the kind of feedback that is applicable to this state if (sscanf(line, "%s", tmpString) != 1) throwError("The kind of feedback to be used for a trajectory must be specified (e.g. linear)"); delete bFeedback; bFeedback = NULL; if (strncmp(tmpString, "linear", 6) == 0){ bFeedback = new LinearBalanceFeedback(); bFeedback->loadFromFile(f); }else throwError("Unrecognized type of feedback: \'%s\'", line); break; case CON_BASE_TRAJECTORY_START: //read in the base trajectory SimBiConState::readTrajectory1D(f, baseTraj, CON_BASE_TRAJECTORY_END); break; case CON_REVERSE_ANGLE_ON_STANCE: if (strncmp(trim(line), "left", 4) == 0) reverseAngleOnLeftStance = true; else if (strncmp(trim(line), "right", 5) == 0) reverseAngleOnRightStance = true; else throwError("When using the \'startingStance\' keyword, \'left\' or \'right\' must be specified!"); break; case CON_NOT_IMPORTANT: tprintf("Ignoring input line: \'%s\'\n", line); break; default: throwError("Incorrect SIMBICON input file: \'%s\' - unexpected line.", buffer); } } throwError("Incorrect SIMBICON input file: No \'/trajectory\' found ", buffer); }
int UnitMain() { #ifdef SYLKFILE_UNIT SylkFile slk("D:\\TestDir\\mpq\\Units\\AbilityData.slk"); slk.save("D:\\TestDir\\mpq\\UnitsCopy\\AbilityData.slk"); slk.save("D:\\TestDir\\mpq\\UnitsCopy\\AbilityData.comp.slk", true); slk.gen_indexs(); #endif //SYLKFILE_UNIT #ifdef SYLKRECORD_UNIT SylkRecord record; record.parser("C;X1;Y13;K\"wild\""); cout<<"Type="<<record.get_type()<<endl; cout<<"X="<<record.get_x()<<endl; cout<<"Y="<<record.get_y()<<endl; cout<<"Value="<<record.get_value()<<endl; #endif //SYLKRECORD_UNIT #ifdef CONVERT_UNIT //SylkFile slk("D:\\TestDir\\mpq\\Units\\AbilityData.slk"); //int i, line = slk.get_y(); //for (i=2; i<=line; i++) //{ // string idStr=slk.getTableData(1, i); // clog << idStr << " => " << id2int(idStr) <<endl; //} //char bytes[]={1,0,0,0}; //convertInt(bytes); string trimStr=" //townhall tier 1 dependency"; lTrim(trimStr); clog<<trimStr<<endl; #endif // IDCONVERT_UNIT #ifdef PROFILE_PARAM_UNIT ProfileParam param; param.parse("Art=ReplaceableTextures\\CommandButtons\\BTNReplenishManaOn.blp"); param.parse("Buttonpos=0,2"); cout<<param.to_string()<<endl; #endif // PROFILE_PARAM_UNIT #ifdef PROFILE_NODE_UNIT ProfileNode node, node2; node.init("Ucrl"); node.add_param("Art=ReplaceableTextures\\CommandButtons\\BTNHeroCryptLord.blp"); node.add_param("Buttonpos=0,1"); node.add_param("RequiresCount=3"); node.add_param("Requires="); node2.init("Ucrl"); node2.add_param("Requires1=unp1"); node2.add_param("Requires2=unp2"); node2.add_param("Specialart=Objects\\Spawnmodels\\Undead\\UndeadLargeDeathExplode\\UndeadLargeDeathExplode.mdl"); node2.add_param("Attachmentanimprops=medium"); node2.add_param("ScoreScreenIcon=UI\\Glues\\ScoreScreen\\scorescreen-hero-cryptlord.blp"); //cout<<node.to_string()<<endl; //cout<<node2.to_string()<<endl; node.merge(node2); cout<<node.to_string()<<endl; #endif // PROFILE_NODE_UNIT #ifdef PROFILE_UNIT TextFile profile; profile.load("D:\\TestDir\\mpq\\Units_126\\ItemFunc.txt"); profile.save("D:\\TestDir\\mpq\\UnitsCopy\\ItemFunc.txt"); #endif // PROFILE_UNIT #ifdef W3OFILE_UNIT W3_File w3a; w3a.load("D:\\TestDir\\mpq\\war3map.w3a"); w3a.save("D:\\TestDir\\mpq\\war3map_copy.w3a"); #endif // W3OFile_UNIT return 0; }
/** This method loads all the pertinent information regarding the simbicon controller from a file. */ void SimBiController::loadFromFile(char* fName){ if (fName == NULL) throwError("NULL file name provided."); FILE *f = fopen(fName, "r"); if (f == NULL) throwError("Could not open file: %s", fName); //to be able to load multiple controllers from multiple files, //we will use this offset to make sure that the state numbers //mentioned in each input file are updated correctly int stateOffset = this->states.size(); SimBiConState* tempState; int tempStateNr = -1; //have a temporary buffer used to read the file line by line... char buffer[200]; //this is where it happens. while (!feof(f)){ //get a line from the file... fgets(buffer, 200, f); if (feof(f)) break; if (strlen(buffer)>195) throwError("The input file contains a line that is longer than ~200 characters - not allowed"); char *line = lTrim(buffer); int lineType = getConLineType(line); switch (lineType) { case CON_PD_GAINS_START: readGains(f); break; case CON_STATE_START: tempState = new SimBiConState(); sscanf(line, "%d", &tempStateNr); if (tempStateNr != stateOffset + this->states.size()) throwError("Inccorect state offset specified: %d", tempStateNr); states.push_back(tempState); tempState->readState(f, stateOffset); //now we have to resolve all the joint names (i.e. figure out which joints they apply to). resolveJoints(tempState); break; case CON_STANCE_HIP_DAMPING: sscanf(line, "%lf", &stanceHipDamping); break; case CON_STANCE_HIP_MAX_VELOCITY: sscanf(line, "%lf", &stanceHipMaxVelocity); break; case CON_ROOT_PRED_TORQUE_SCALE: sscanf(line, "%lf", &rootPredictiveTorqueScale); break; case CON_CHARACTER_STATE: character->loadReducedStateFromFile(trim(line)); strcpy(initialBipState, trim(line)); break; case CON_START_AT_STATE: if (sscanf(line, "%d", &tempStateNr) != 1) throwError("A starting state must be specified!"); transitionToState(tempStateNr); startingState = tempStateNr; break; case CON_COMMENT: break; case CON_STARTING_STANCE: if (strncmp(trim(line), "left", 4) == 0){ setStance(LEFT_STANCE); startingStance = LEFT_STANCE; } else if (strncmp(trim(line), "right", 5) == 0){ setStance(RIGHT_STANCE); startingStance = RIGHT_STANCE; } else throwError("When using the \'reverseTargetOnStance\' keyword, \'left\' or \'right\' must be specified!"); break; case CON_NOT_IMPORTANT: tprintf("Ignoring input line: \'%s\'\n", line); break; default: throwError("Incorrect SIMBICON input file: \'%s\' - unexpected line.", buffer); } } }
char* readLine(FILE* file) { char str[255]; fscanf(file, "%s", str); return lTrim(str, ' '); }
char* trim(char* szX) { szX = lTrim(szX); szX = rTrim(szX); return szX; }
char* trim(char* string){ return lTrim(rTrim(string)); }
void ListPatches (HWND hW) { int i, tmpi, filesize, totalPatch=0, totalSize=0; char tmpStr[MAX_PATH], *fileData; WIN32_FIND_DATA FindData; HANDLE Find; FILE *fp; //clear listbox's SendDlgItemMessage(hW, IDC_PATCHCRCLIST, (UINT)LB_RESETCONTENT, (WPARAM)NULL, (LPARAM)NULL); SendDlgItemMessage(hW, IDC_PATCHNAMELIST, (UINT)LB_RESETCONTENT, (WPARAM)NULL, (LPARAM)NULL); //sprintf(tmpStr,"%s*.pnach", Config.PatchDir) sprintf(tmpStr, "patches\\*.pnach"); Find = FindFirstFile(tmpStr, &FindData); do { if (Find==INVALID_HANDLE_VALUE) break; sprintf(tmpStr,"%s", FindData.cFileName); //add file name to crc list SendDlgItemMessage(hW, IDC_PATCHCRCLIST, (UINT) LB_ADDSTRING, (WPARAM)NULL, (LPARAM)tmpStr); //sprintf(tmpStr,"%s%s", Config.PatchDir, FindData.cFileName) sprintf(tmpStr,"patches\\%s", FindData.cFileName); fp = fopen(tmpStr, "r"); if (fp == NULL) break; fseek(fp, 0, SEEK_END); filesize = ftell(fp); totalSize += filesize; fseek(fp, 0, SEEK_SET); fileData = (char *) malloc(filesize+1024); sprintf(fileData,""); //read file while((tmpi=fgetc(fp)) != EOF) sprintf(fileData,"%s%c",fileData,tmpi); //small hack :p for(i=0;i<filesize;i++) { if (fileData[i] == 'g' && fileData[i+1] == 'a' && fileData[i+2] == 'm' && fileData[i+3] == 'e' && fileData[i+4] == 't' && fileData[i+5] == 'i' && fileData[i+6] == 't' && fileData[i+7] == 'l' && fileData[i+8] == 'e' && fileData[i+9] == '=') { for(i=i+10,tmpi=0;i<filesize;i++,tmpi++) { if (fileData[i] == '\n') break; tmpStr[tmpi] = fileData[i]; } tmpStr[tmpi] = '\0'; break; } } //remove " in the string for (i=0,tmpi=0; tmpStr[i]!='\0'; i++) if (tmpStr[i] != '"') tmpStr[tmpi++] = tmpStr[i]; tmpStr[tmpi] = '\0'; //remove spaces at the left of the string sprintf(tmpStr,lTrim(tmpStr)); sprintf(tmpStr,"%s (%s)",tmpStr,FindData.cFileName); //add game name to patch name list SendDlgItemMessage(hW, IDC_PATCHNAMELIST, (UINT) LB_ADDSTRING, (WPARAM)NULL, (LPARAM)tmpStr); totalPatch++; sprintf(fileData,""); fclose(fp); } while (FindNextFile(Find,&FindData)); if (Find!=INVALID_HANDLE_VALUE) FindClose(Find); sprintf(tmpStr,"Patches Browser | Patches Found: %d | Total Filesize: %.2f KB", totalPatch,(float)totalSize/1024); SetWindowText(hW, tmpStr); }
std::string StringUtil::trim(const std::string& str,const std::string& spaces) { return lTrim(rTrim(str,spaces),spaces); }