uint64 File::GetPartitionDeviceStartOffset () const { #ifdef TC_LINUX // HDIO_GETGEO ioctl is limited by the size of long TextReader tr ("/sys/block/" + string (Path.ToHostDriveOfPartition().ToBaseName()) + "/" + string (Path.ToBaseName()) + "/start"); string line; tr.ReadLine (line); return StringConverter::ToUInt64 (line) * GetDeviceSectorSize(); #elif defined (TC_MACOSX) #ifndef DKIOCGETBASE # define DKIOCGETBASE _IOR('d', 73, uint64) #endif uint64 offset; throw_sys_sub_if (ioctl (FileHandle, DKIOCGETBASE, &offset) == -1, wstring (Path)); return offset; #elif defined (TC_SOLARIS) struct extpart_info partInfo; throw_sys_sub_if (ioctl (FileHandle, DKIOCEXTPARTINFO, &partInfo) == -1, wstring (Path)); return partInfo.p_start * GetDeviceSectorSize(); #else throw NotImplemented (SRC_POS); #endif }
TEST(TextWriterTest, t2) { std::string outfile(Support::temppath("utm17.txt")); std::string infile(Support::datapath("text/utm17_2.txt")); FileUtils::deleteFile(outfile); TextReader r; Options ro; ro.add("filename", infile); r.setOptions(ro); TextWriter w; Options wo; wo.add("filename", outfile); wo.add("order", "X,Y,Z"); wo.add("quote_header", false); wo.add("precision", 2); wo.add("delimiter", " "); w.setOptions(wo); w.setInput(r); PointTable t; w.prepare(t); w.execute(t); EXPECT_EQ(Support::compare_text_files(infile, outfile), true); }
void compareTextLasStreaming(const std::string& textFilename, const std::string& lasFilename) { std::string tempname(Support::temppath("testlas.las")); FileUtils::deleteFile(tempname); TextReader t; Options to; to.add("filename", textFilename); t.setOptions(to); LasWriter w; Options wo; wo.add("filename", tempname); w.setInput(t); w.setOptions(wo); FixedPointTable in(1000); w.prepare(in); w.execute(in); LasReader l1; Options l1o; l1o.add("filename", lasFilename); l1.setOptions(l1o); LasReader l2; Options l2o; l2o.add("filename", tempname); l2.setOptions(l2o); PointTable t1; l1.prepare(t1); PointViewSet s1 = l1.execute(t1); EXPECT_EQ(s1.size(), 1U); PointViewPtr v1 = *s1.begin(); PointTable t2; l2.prepare(t2); PointViewSet s2 = l2.execute(t2); EXPECT_EQ(s2.size(), 1U); PointViewPtr v2 = *s2.begin(); EXPECT_EQ(v1->size(), v2->size()); // Validate some point data. for (PointId i = 0; i < v1->size(); ++i) { EXPECT_DOUBLE_EQ(v1->getFieldAs<double>(Dimension::Id::X, i), v2->getFieldAs<double>(Dimension::Id::X, i)); EXPECT_DOUBLE_EQ(v1->getFieldAs<double>(Dimension::Id::Y, i), v2->getFieldAs<double>(Dimension::Id::Y, i)); EXPECT_DOUBLE_EQ(v1->getFieldAs<double>(Dimension::Id::Z, i), v2->getFieldAs<double>(Dimension::Id::Z, i)); } }
TEST(TextReaderTest, badheader) { TextReader t; Options to; to.add("filename", Support::datapath("text/badheader.txt")); t.setOptions(to); PointTable tt; EXPECT_THROW(t.prepare(tt), pdal_error); }
static char _skip_space(TextReader &r) { char c = 0; std::string comment; while ((c = r.nextnotspace()) == ';') { comment.clear(); r.until(comment, '\n'); } return r.at(); }
int TestMD5() { MD5Hash md5; const char *teststring = NULL; size_t length = 0; /* These tests are from FIPS PUB 180-1 */ teststring = ""; length = strlen(teststring); md5.Process(teststring, length); TEST_ASSERT(strcmp(md5.ToString(), "d41d8cd98f00b204e9800998ecf8427e") == 0); teststring = "a"; length = strlen(teststring); md5.Process(teststring, length); TEST_ASSERT(strcmp(md5.ToString(), "0cc175b9c0f1b6a831c399e269772661") == 0); teststring = "abc"; length = strlen(teststring); md5.Process(teststring, length); TEST_ASSERT(strcmp(md5.ToString(), "900150983cd24fb0d6963f7d28e17f72") == 0); teststring = "message digest"; length = strlen(teststring); md5.Process(teststring, length); TEST_ASSERT(strcmp(md5.ToString(), "f96b697d7cb7938d525a2f31aaf161d0") == 0); teststring = "abcdefghijklmnopqrstuvwxyz"; length = strlen(teststring); md5.Process(teststring, length); TEST_ASSERT(strcmp(md5.ToString(), "c3fcd3d76192e4007dfb496cca67e13b") == 0); teststring = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; length = strlen(teststring); md5.Process(teststring, length); TEST_ASSERT(strcmp(md5.ToString(), "d174ab98d277d9f5a5611c2c9f419d9f") == 0); teststring = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"; length = strlen(teststring); md5.Process(teststring, length); TEST_ASSERT(strcmp(md5.ToString(), "57edf4a22be3c955ac49da2e2107b67a") == 0); MD5Hash otherhash; otherhash.Process("cheese", 6); TEST_ASSERT(otherhash != md5 && md5 != otherhash); otherhash.Process(teststring, length); TEST_ASSERT(otherhash == md5 && md5 == otherhash); #ifdef FILE_CHECKSUM TextReader file; file.Open("testfile"); md5.Process((CoreIOReader *)&file); TEST_ASSERT(strcmp(md5.ToString(), "bc2471d759c6ae2eb44482f571b02a40") == 0); #endif return 0; }
void Gesture::LoadTrainingData( char *filename ) { TextReader *reader = g_app->m_resource->GetTextReader(filename); DarwiniaReleaseAssert(reader && reader->IsOpen(), "Couldn't open Gesture data file"); reader->ReadLine(); int numSymbols = atoi(reader->GetNextToken()); m_symbols.SetSize( numSymbols ); for( int c = 0; c < numSymbols; ++c ) { m_symbols.PutData( GestureSymbol(), c ); Classification *theClass = &m_symbols[c].m_classes; reader->ReadLine(); theClass->m_nextTrainer = atoi(reader->GetNextToken()); if( theClass->m_nextTrainer > 0 ) { reader->ReadLine(); for( int t = 0; t < theClass->m_nextTrainer; ++t ) { FeatureSet *fs = &theClass->m_trainers[t]; for( int f = 0; f <= GESTURE_MAX_FEATURES; ++f ) { fs->f[f] = atof(reader->GetNextToken()); } } } } delete reader; TrainSystem(); }
bool CSVData::loadFromTextReader(TextReader& reader, const StringView separators, const StringView quotes, const StringView escapes) { if (!reader) { return false; } const boost::escaped_list_separator<char32> separator(escapes.to_string(), separators.to_string(), quotes.to_string()); String str; m_data.clear(); while (reader.readLine(str)) { try { const boost::tokenizer<boost::escaped_list_separator<char32>, String::const_iterator, String> tokens(str, separator); m_data.emplace_back(tokens.begin(), tokens.end()); } catch (boost::exception&) { str.replace(U"\\", U"\\\\"); const boost::tokenizer<boost::escaped_list_separator<char32>, String::const_iterator, String> tokens(str, separator); m_data.emplace_back(tokens.begin(), tokens.end()); } } return true; }
void Init(){ Text = TxtReader.GetString(); for (int i = 0; i < 256; i++){ Chars[i].SelfCh = i - 128; Chars[i].Freq = 0; } }
void EarthData::LoadCoastlines() { double startTime = GetHighResTime(); m_islands.EmptyAndDelete(); int numIslands = 0; char coastFile[1024]; if( g_preferences->GetInt(PREFS_GRAPHICS_LOWRESWORLD) == 0 ) { strcpy(coastFile, "data/earth/coastlines.dat"); } else { strcpy(coastFile, "data/earth/coastlines-low.dat"); } TextReader *coastlines = g_fileSystem->GetTextReader( coastFile ); AppAssert( coastlines && coastlines->IsOpen() ); Island *island = NULL; while( coastlines->ReadLine() ) { char *line = coastlines->GetRestOfLine(); if( line[0] == 'b' ) { if( island ) { m_islands.PutData( island ); } island = new Island(); ++numIslands; } else { float longitude, latitude; sscanf( line, "%f %f", &longitude, &latitude ); island->m_points.PutData( new Vector3<float>( longitude, latitude, 0.0f ) ); } } delete coastlines; double totalTime = GetHighResTime() - startTime; AppDebugOut( "Parsing Coastline data (%d islands) : %dms\n", numIslands, int( totalTime * 1000.0f ) ); }
TEST(TextReaderTest, strip_whitespace_from_dimension_names) { TextReader reader; Options options; options.add("filename", Support::datapath("text/crlf_test.txt")); reader.setOptions(options); PointTable table; reader.prepare(table); PointViewSet pointViewSet = reader.execute(table); PointViewPtr pointViewPtr = *pointViewSet.begin(); for (PointId i = 0; i < pointViewPtr->size(); ++i) { EXPECT_EQ( i, pointViewPtr->getFieldAs<uint16_t>(Dimension::Id::Intensity, i)); } }
void DescrTextChunk::read(TextReader& reader) { std::string offsets; reader.readLine(offsets); std::string frames; reader.readLine(frames); uint32_t numLines = 0; reader.readUInt32(numLines); m_descrText.clear(); for (uint32_t i = 0; i < numLines; ++i) { std::string line; reader.readLine(line); m_descrText.append(line).append("\n"); } }
int TestSHA256() { SHA256Hash sha256; const char *teststring = NULL; size_t length = 0; /* These tests are from FIPS PUB 180-1 */ teststring = "abc"; length = strlen(teststring); sha256.Process(teststring, length); TEST_ASSERT(strcmp(sha256.ToString(), "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") == 0); teststring = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; length = strlen(teststring); sha256.Process(teststring, length); TEST_ASSERT(strcmp(sha256.ToString(), "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1") == 0); SHA256Hash otherhash; otherhash.Process("cheese", 6); TEST_ASSERT(otherhash != sha256 && sha256 != otherhash); otherhash.Process(teststring, length); TEST_ASSERT(otherhash == sha256 && sha256 == otherhash); #ifdef HIGH_INTENSITY char *tempstring = new char[1000001]; memset(tempstring, 'a', 1000000); tempstring[1000000] = '\0'; length = strlen(tempstring); sha256.Process(tempstring, length); TEST_ASSERT(strcmp(sha256.ToString(), "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0") == 0); delete [] tempstring; #endif #ifdef FILE_CHECKSUM TextReader file; file.Open("testfile"); sha256.Process((CoreIOReader *)&file); TEST_ASSERT(strcmp(sha256.ToString(), "e6f106d98b2937a68a1700c747e37c4d942a364ee0a529cb5b49e9e4cf66b7fe") == 0); #endif return 0; }
int TestSHA1() { SHA1Hash sha1; const char *teststring = NULL; size_t length = 0; /* These tests are from FIPS PUB 180-1 */ teststring = "abc"; length = strlen(teststring); sha1.Process(teststring, length); TEST_ASSERT(strcmp(sha1.ToString(), "a9993e364706816aba3e25717850c26c9cd0d89d") == 0); teststring = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; length = strlen(teststring); sha1.Process(teststring, length); TEST_ASSERT(strcmp(sha1.ToString(), "84983e441c3bd26ebaae4aa1f95129e5e54670f1") == 0); SHA1Hash otherhash; otherhash.Process("cheese", 6); TEST_ASSERT(otherhash != sha1 && sha1 != otherhash); otherhash.Process(teststring, length); TEST_ASSERT(otherhash == sha1 && sha1 == otherhash); #ifdef HIGH_INTENSITY char *tempstring = new char[1000001]; memset(tempstring, 'a', 1000000); tempstring[1000000] = '\0'; length = strlen(tempstring); sha1.Process(tempstring, length); TEST_ASSERT(strcmp(sha1.ToString(), "34aa973cd4c4daa4f61eeb2bdbad27316534016f") == 0); delete [] tempstring; #endif #ifdef FILE_CHECKSUM TextReader file; file.Open("testfile"); sha1.Process((CoreIOReader *)&file); TEST_ASSERT(strcmp(sha1.ToString(), "951a6307067df1931ee1637a57ea4b9ad4a01a7c") == 0); #endif return 0; }
TEST(TextReaderTest, insertHeader) { TextReader reader; Options options; options.add("header", "A,B,C,G"); options.add("filename", Support::datapath("text/crlf_test.txt")); reader.setOptions(options); PointTable table; reader.prepare(table); PointViewSet pointViewSet = reader.execute(table); PointViewPtr pointViewPtr = *pointViewSet.begin(); EXPECT_EQ(pointViewPtr->size(), 11U); PointLayoutPtr layout = table.layout(); EXPECT_TRUE(layout->findDim("A") != Dimension::Id::Unknown); EXPECT_TRUE(layout->findDim("B") != Dimension::Id::Unknown); EXPECT_TRUE(layout->findDim("C") != Dimension::Id::Unknown); EXPECT_TRUE(layout->findDim("G") != Dimension::Id::Unknown); }
int main() { cudaEvent_t start; cudaEvent_t end; float duration; const float overestimateRate = 0.01f; const float errorRate = 0.01f; Tokenizer tokenizer( overestimateRate, errorRate ); /************** Test counting string tokens *************/ TextReader reader; cudaEventCreate( &start ); cudaEventRecord( start, 0 ); reader.Read(); tokenizer.StartTokenizing( reader.GetCharBuffer(), reader.GetOffsetBuffer(), reader.GetCharBufferSize(), reader.GetOffsetBufferSize() ); cudaEventCreate( &end ); cudaEventRecord( end, 0 ); cudaEventSynchronize( end ); cudaEventElapsedTime( &duration, start, end ); printf( "Time taken: %.3lf milliseconds\n", duration ); tokenizer.GetFrequency( "a" ); }
void compareTextLas(const std::string& textFilename, const std::string& lasFilename) { TextReader t; Options to; to.add("filename", textFilename); t.setOptions(to); LasReader l; Options lo; lo.add("filename", lasFilename); l.setOptions(lo); PointTable tt; t.prepare(tt); PointViewSet ts = t.execute(tt); EXPECT_EQ(ts.size(), 1U); PointViewPtr tv = *ts.begin(); PointTable lt; l.prepare(lt); PointViewSet ls = l.execute(lt); EXPECT_EQ(ls.size(), 1U); PointViewPtr lv = *ls.begin(); EXPECT_EQ(tv->size(), lv->size()); // Validate some point data. for (PointId i = 0; i < lv->size(); ++i) { EXPECT_DOUBLE_EQ(tv->getFieldAs<double>(Dimension::Id::X, i), lv->getFieldAs<double>(Dimension::Id::X, i)); EXPECT_DOUBLE_EQ(tv->getFieldAs<double>(Dimension::Id::Y, i), lv->getFieldAs<double>(Dimension::Id::Y, i)); EXPECT_DOUBLE_EQ(tv->getFieldAs<double>(Dimension::Id::Z, i), lv->getFieldAs<double>(Dimension::Id::Z, i)); } }
// Make sure that dimension names containing digits works TEST(RangeFilterTest, case_1659) { TextReader reader; Options ops; ops.add("filename", Support::datapath("text/numeric_dim.txt")); reader.setOptions(ops); Options rangeOps; rangeOps.add("limits", "Eigenvalue0[:35]"); RangeFilter filter; filter.setOptions(rangeOps); filter.setInput(reader); PointTable table; filter.prepare(table); PointViewSet viewSet = filter.execute(table); PointViewPtr view = *viewSet.begin(); EXPECT_EQ(1u, viewSet.size()); EXPECT_EQ(3u, view->size()); }
int main(){ int t, a[10] = {87,31567,6148,64,36498,897,699,88,61,477}; Init(); cout << TxtReader.GetString(); for (int i = 0; i < 10; i++){ //heap.Insert(a[i], min); } for (int i = 0; i < 10; i++){ //cout<<heap.Get(min)<<endl; } return 0; }
void EarthData::LoadBorders() { double startTime = GetHighResTime(); m_borders.EmptyAndDelete(); int numIslands = 0; Island *island = NULL; TextReader *international = g_fileSystem->GetTextReader( "data/earth/international.dat" ); AppAssert( international && international->IsOpen() ); while( international->ReadLine() ) { char *line = international->GetRestOfLine(); if( line[0] == 'b' ) { if( island ) { m_borders.PutData( island ); ++numIslands; } island = new Island(); } else { float longitude, latitude; sscanf( line, "%f %f", &longitude, &latitude ); island->m_points.PutData( new Vector3<float>( longitude, latitude, 0.0f ) ); } } delete international; double totalTime = GetHighResTime() - startTime; AppDebugOut( "Parsing International data (%d islands) : %dms\n", numIslands, int( totalTime * 1000.0f ) ); }
void OpponentDescription::read(TextReader& reader) { // TODO: throw on error reader.readLine(m_opponentName); reader.readLine(m_driverName); reader.readUInt32(m_id); reader.readUInt32(m_strength); std::string m_avail; reader.readLine(m_avail); m_networkAvail = parseNetAvail(m_avail); reader.readLine(m_flic1File); reader.readLine(m_textfFile); reader.readLine(m_flic2File); uint32_t descrChunksCnt = 0; reader.readUInt32(descrChunksCnt); for (uint32_t i = 0; i < descrChunksCnt; ++i) { DescrTextChunk chunk; chunk.read(reader); } }
bool LanguageTable::LoadLanguageCaption( Language *lang ) { TextReader *in = g_fileSystem->GetTextReader( lang->m_path ); if( !in ) return false; if( !in->IsOpen() ) { delete in; return false; } // // Read all the phrases from the language file while (in->ReadLine()) { if (!in->TokenAvailable()) continue; char *key = in->GetNextToken(); char *aString = in->GetRestOfLine(); if( key && aString && stricmp( key, "lang" ) == 0 ) { // // Strip trailing '\n' int stringLength = strlen( aString ); if( aString[stringLength-1] == '\n' ) { aString[stringLength-1] = '\x0'; } if( aString[stringLength-2] == '\r' ) { aString[stringLength-2] = '\x0'; } snprintf( lang->m_caption, sizeof(lang->m_caption), aString ); lang->m_caption[ sizeof(lang->m_caption) - 1 ] = '\0'; delete in; return true; } } delete in; return false; }
void EntityBlueprint::Initialise() { TextReader *theFile = g_app->m_resource->GetTextReader("stats.txt"); AppReleaseAssert(theFile && theFile->IsOpen(), "Couldn't open stats.txt"); int entityIndex = 0; while( theFile->ReadLine() ) { if (!theFile->TokenAvailable()) continue; AppReleaseAssert(entityIndex < Entity::NumEntityTypes, "Too many entity blueprints defined"); m_names[entityIndex] = strdup(theFile->GetNextToken()); m_stats[entityIndex][0] = iv_atof(theFile->GetNextToken()); m_stats[entityIndex][1] = iv_atof(theFile->GetNextToken()); m_stats[entityIndex][2] = iv_atof(theFile->GetNextToken()); ++entityIndex; } delete theFile; }
void LanguageTable::LoadLanguage(char *_filename, BTree<char *> &_langTable ) { TextReader *in = g_fileSystem->GetTextReader(_filename); AppReleaseAssert(in && in->IsOpen(), "Couldn't open language file %s", _filename ); // // Read all the phrases from the language file while (in->ReadLine()) { if (!in->TokenAvailable()) continue; char *key = in->GetNextToken(); #ifdef TARGET_OS_MACOSX // // Special case hack // If this is the Mac version and there is a replacement string // Use the replacement string instead #define MACOSX_MARKER "macosx_" if( strncmp( key, MACOSX_MARKER, strlen(MACOSX_MARKER) ) == 0 ) { key += strlen(MACOSX_MARKER); } #endif // // Make sure the this key isn't already used if(_langTable.LookupTree(key)) { //AppDebugOut( "Warning : found duplicate key '%s' in language file %s\n", key, _filename ); _langTable.RemoveData( key ); } char *aString = strdup( in->GetRestOfLine() ); // // Make sure a language key always has a some text with it if( !aString || aString[0] == '\0' ) { AppDebugOut( "Warning : found key '%s' with no translation in language file %s\n", key, _filename ); if( aString ) { delete [] aString; } continue; } // // Convert the string "\n" into a genuine '\n' for( unsigned int i = 0; i < strlen(aString)-1; ++i ) { if( aString[i] == '\\' && aString[i+1] == 'n' ) { aString[i] = ' '; aString[i+1] = '\n'; } } // // Strip trailing '\n' int stringLength = strlen( aString ); if( aString[stringLength-1] == '\n' ) { aString[stringLength-1] = '\x0'; } if( aString[stringLength-2] == '\r' ) { aString[stringLength-2] = '\x0'; } _langTable.PutData(key, aString); } delete in; }
Game::Game() : m_victoryTimer(-1), m_recalcTimer(0), m_winner(-1), m_maxGameTime(-1), m_gameTimeWarning(false), m_lockVictoryTimer(false), m_lastKnownDefcon(5), m_gameMode(-1) { // // Load game options TextReader *in = g_fileSystem->GetTextReader( "data/gameoptions.txt" ); AppAssert(in && in->IsOpen()); while( in->ReadLine() ) { if( !in->TokenAvailable() ) continue; char *param = in->GetNextToken(); GameOption *option = new GameOption(); m_options.PutData( option ); strcpy( option->m_name, param ); option->m_min = atof( in->GetNextToken() ); option->m_max = atof( in->GetNextToken() ); option->m_default = atof( in->GetNextToken() ); option->m_change = atoi( in->GetNextToken() ); if( option->m_change == 0 ) { // Drop down menu - so load the sub options int numOptions = option->m_max - option->m_min; numOptions ++; for( int i = 0; i < numOptions; ++i ) { in->ReadLine(); char *subOption = strdup( in->GetRestOfLine() ); // Strip trailing \n and \r int stringLength = strlen(subOption); if( subOption[stringLength-1] == '\n' ) subOption[stringLength-1] = '\x0'; if( subOption[stringLength-2] == '\r' ) subOption[stringLength-2] = '\x0'; option->m_subOptions.PutData( subOption ); } } if( option->m_change == -1 ) { // String - load default in->ReadLine(); strcpy( option->m_currentString, in->GetRestOfLine() ); } } delete in; ResetOptions(); #ifdef TESTBED GetOption("MaxTeams")->m_default = 2; GetOption("MaxTeams")->m_currentValue = 2; GetOption("MaxGameRealTime")->m_default = 15; GetOption("MaxGameRealTime")->m_currentValue = 15; #endif m_score.Initialise(MAX_TEAMS); m_nukeCount.Initialise(MAX_TEAMS); m_totalNukes.Initialise(MAX_TEAMS); for( int t = 0; t < MAX_TEAMS; ++t ) { m_score[t] = 0; m_nukeCount[t] = 0; m_totalNukes[t] = 0; } }
Tutorial::Tutorial( int _startChapter ) : m_currentChapter(-1), m_nextChapter(-1), m_nextChapterTimer(0.0f), m_objectHighlight(-1), m_miscTimer(-1.0f), m_worldInitialised(false), m_startLevel(_startChapter) { m_levelName[0] = '\x0'; SetCurrentLevel(1); // // Parse the tutorial data file TextReader *reader = g_fileSystem->GetTextReader( "data/tutorial.txt" ); AppAssert( reader && reader->IsOpen() ); while( reader->ReadLine() ) { if( !reader->TokenAvailable() ) continue; char *chapterHeading = reader->GetNextToken(); AppAssert( stricmp( chapterHeading, "CHAPTER" ) == 0 ); TutorialChapter *chapter = new TutorialChapter(); m_chapters.PutData( chapter ); chapter->m_name = strdup( reader->GetNextToken() ); char temp[256]; sprintf( temp, "tutorial_%s", chapter->m_name ); chapter->m_message = strdup( temp ); sprintf( temp, "tutorial_%s_obj", chapter->m_name ); chapter->m_objective = strdup( temp ); while( reader->ReadLine() ) { if( !reader->TokenAvailable() ) continue; char *field = reader->GetNextToken(); if( stricmp( field, "END" ) == 0 ) break; char *value = reader->GetRestOfLine(); if( value ) value[ strlen(value) - 1 ] = '\x0'; if( stricmp( field, "MESSAGE" ) == 0 ) chapter->m_message = strdup(value); if( stricmp( field, "OBJECTIVE" ) == 0 ) chapter->m_objective = strdup(value); if( stricmp( field, "WINDOWHIGHLIGHT" ) == 0 ) chapter->m_windowHighlight = strdup(value); if( stricmp( field, "BUTTONHIGHLIGHT" ) == 0 ) chapter->m_buttonHighlight = strdup(value); if( stricmp( field, "NEXTCLICKABLE" ) == 0 ) { chapter->m_nextClickable = true; chapter->m_objective = strdup( "tutorial_clicknext" ); } if( stricmp( field, "RESTARTCLICKABLE" ) == 0 ) { chapter->m_restartClickable = true; chapter->m_objective = strdup("tutorial_restart_mission"); } } } }
void EarthData::LoadCities() { float startTime = GetHighResTime(); m_cities.EmptyAndDelete(); TextReader *cities = g_fileSystem->GetTextReader( "data/earth/cities.dat" ); AppAssert( cities && cities->IsOpen() ); int numCities = 0; while( cities->ReadLine() ) { char *line = cities->GetRestOfLine(); char name[256]; char country[256]; float latitude, longitude; int population; int capital; strncpy( name, line, 40 ); for( int i = 39; i >= 0; --i ) { if( name[i] != ' ' ) { name[i+1] = '\x0'; break; } } strncpy( country, line+41, 40 ); for( int i = 39; i >= 0; --i ) { if( country[i] != ' ' ) { country[i+1] = '\x0'; break; } } sscanf( line+82, "%f %f %d %d", &longitude, &latitude, &population, &capital ); City *city = new City(); city->m_name = strdup( strupr(name) ); city->m_country = strdup( strupr(country) ); city->m_longitude = Fixed::FromDouble(longitude); city->m_latitude = Fixed::FromDouble(latitude); city->m_population = population; city->m_capital = capital; city->SetRadarRange( Fixed::FromDouble(sqrtf( sqrtf(city->m_population) ) / 4.0f) ); m_cities.PutData( city ); ++numCities; } delete cities; float totalTime = GetHighResTime() - startTime; AppDebugOut( "Parsing City data (%d cities) : %dms\n", numCities, int( totalTime * 1000.0f ) ); }
void InputManager::parseInputPrefs( TextReader &reader, bool replace ) { int line = 1; // FIXME: always log to file on OS X, not to Console, because we're getting // a number of spurious error messages. #if defined(TARGET_OS_MACOSX) || defined(TARGET_DEBUG) char fullFileName[512]; snprintf( fullFileName, sizeof(fullFileName), "%sinputprefs_debug.txt", g_app->GetProfileDirectory() ); fullFileName[ sizeof(fullFileName) - 1 ] = '\0'; ofstream derr( fullFileName ); #else ostream &derr = cout; #endif while ( reader.ReadLine() ) { // derr << "Line " << line++ << ": "; bool iconline = false; char *control = reader.GetNextToken(); if ( control ) { char *eq = reader.GetNextToken(); if ( !eq || strcmp( eq, "=" ) != 0 ) { if ( eq && !strcmp( eq, "~" ) ) { iconline = true; } else { derr << "Assignment not found." << endl; continue; } } string inputspec = reader.GetRestOfLine(); controltype_t control_id = getControlID( control ); if ( control_id >= 0 ) { if ( iconline ) { if ( inputspec != "" ) { unsigned len = inputspec.length() - 1; if ( inputspec[ len ] == '\n' ) inputspec = inputspec.substr( 0, len-- ); if ( inputspec[ len ] == '\r' ) inputspec = inputspec.substr( 0, len ); bindings.setIcon( control_id, inputspec ); } else derr << "Empty icon line." << endl; continue; } InputSpec spec; string err; InputParserState state; if ( PARSE_SUCCESS( state = parseInputSpecString( inputspec, spec, err ) ) ) { if ( !bindings.bind( control_id, spec, replace ) ) derr << "Binding failed." << endl; } else { derr << "Parse failed - " << err << " (state = " << state << ")" << endl; } } else derr << "Control ID not found." << endl; } } }