int DoBdiff( const char *srcPath, const char *tgtPath, const char *name ) { long savings; foff buffsize; int i; // if( !MsgInit() ) exit( EXIT_FAILURE ); /* initialize static variables each time */ SimilarRegions = NULL; DiffRegions = NULL; HoleRegions = NULL; SimilarSize = 0; NumHoles = 0; NumDiffs = 0; DiffSize = 0; HolesInRegion = 0; HoleHeaders = 0; for( i = 0; i < 3; i += 1 ) { HoleCount[i] = 0; } init_diff(); newName = name; EndOld = FileSize( srcPath, &OldCorrection ); EndNew = FileSize( tgtPath, &NewCorrection ); buffsize = ( EndOld > EndNew ) ? ( EndOld ) : ( EndNew ); buffsize += sizeof( PATCH_LEVEL ); OldFile = ReadIn( srcPath, buffsize, EndOld ); NewFile = ReadIn( tgtPath, buffsize, EndNew ); ScanSyncString( SyncString ); FindRegions(); if( NumHoles == 0 && DiffSize == 0 && EndOld == EndNew ) { printf( "Patch file not created - files are identical\n" ); MsgFini(); exit( EXIT_SUCCESS ); } MakeHoleArray(); SortHoleArray(); ProcessHoleArray( 0 ); savings = HolesToDiffs(); WritePatchFile( "", newName ); FreeHoleArray(); VerifyCorrect( tgtPath ); print_stats( savings ); MsgFini(); return ( EXIT_SUCCESS ); }
void main( int argc, char **argv ) { long savings; foff buffsize; algorithm alg; if( !MsgInit() ) exit( EXIT_FAILURE ); alg = ParseArgs( argc, argv ); EndOld = FileSize( argv[1], &OldCorrection ); EndNew = FileSize( argv[2], &NewCorrection ); buffsize = ( EndOld > EndNew ) ? ( EndOld ) : ( EndNew ); buffsize += sizeof( PATCH_LEVEL ); OldFile = ReadIn( argv[1], buffsize, EndOld ); NewFile = ReadIn( argv[2], buffsize, EndNew ); ScanSyncString( SyncString ); switch( alg ) { case ALG_NOTHING: FindRegions(); break; #ifdef USE_DBGINFO case ALG_ONLY_NEW: case ALG_BOTH: SymbolicDiff( alg, argv[1], argv[2] ); break; #endif } if( NumHoles == 0 && DiffSize == 0 && EndOld == EndNew ) { printf( "Patch file not created - files are identical\n" ); MsgFini(); exit( EXIT_SUCCESS ); } MakeHoleArray(); SortHoleArray(); ProcessHoleArray( 0 ); savings = HolesToDiffs(); WritePatchFile( argv[3], newName ); FreeHoleArray(); VerifyCorrect( argv[2] ); print_stats( savings ); MsgFini(); exit( EXIT_SUCCESS ); }
void CServer::msgProc() { TS_PEER_MESSAGE pmsg; memset(&pmsg, 0, sizeof(TS_PEER_MESSAGE)); while (isRunning()) { memset(&pmsg, 0, sizeof(TS_PEER_MESSAGE)); ReadIn(pmsg); MsgHandler(pmsg); } cout << "msg thread exit" << endl; }
void CClientNet::msgProc() { TS_PEER_MESSAGE *pmsg = new TS_PEER_MESSAGE(); memset(pmsg, 0, sizeof(TS_PEER_MESSAGE)); while (isRunning()) { memset(pmsg, 0, sizeof(TS_PEER_MESSAGE)); ReadIn(*pmsg); MsgHandler(*pmsg); } delete pmsg; }
/********************************************************************** * Function Name: Default Constructor * Date : Mar 9, 2013 * Author : hrushi * Comments : * Args : **********************************************************************/ ReadHistLookup::ReadHistLookup(string sPath) : ReadFile(sPath) { try { ReadIn(); } catch(unsigned int err ) { cerr << "Error Reading Look Up File" << endl; throw err; } }
TEST_F(BinaryReaderWriterTest, uint8Test) { std::vector<uint8_t> orig = { 1, 2, 3, 42 }; for (auto const e : orig) { writer.Push(e); } WriteOut(); ReadIn(); for (auto const e : orig) { ASSERT_FALSE(reader.IsEmpty()); EXPECT_TRUE(e == reader.Get<uint8_t>()); } }
TEST_F(BinaryReaderWriterTest, booReflTest) { std::vector<bool> orig = { true, false, true, false, true }; for (auto const e : orig) { writer.Push(e); } WriteOut(); ReadIn(); for (auto const e : orig) { ASSERT_FALSE(reader.IsEmpty()); EXPECT_TRUE(e == reader.Get<bool const&>()); } }
TEST_F(BinaryReaderWriterTest, stdstringTest) { std::vector<std::string> orig = { "This", "is", "a", "test." }; for (auto const& e : orig) { writer.Push(e); } WriteOut(); ReadIn(); for (auto const e : orig) { ASSERT_FALSE(reader.IsEmpty()); EXPECT_TRUE(e == reader.Get<std::string>()); } }
TEST_F(BinaryReaderWriterTest, int32RefTest) { std::vector<int32_t> orig = { 0x12345678, 0x77777777, 0x31337, 42 }; for (auto const e : orig) { writer.Push(e); } WriteOut(); ReadIn(); for (auto const e : orig) { ASSERT_FALSE(reader.IsEmpty()); EXPECT_TRUE(e == reader.Get<int32_t const&>()); } }
TEST_F(BinaryReaderWriterTest, int16RefTest) { std::vector<int16_t> orig = { 0xACE, 0x1234, 0x7777, 0x1, 0x4649 }; for (auto const e : orig) { writer.Push(e); } WriteOut(); ReadIn(); for (auto const e : orig) { ASSERT_FALSE(reader.IsEmpty()); EXPECT_TRUE(e == reader.Get<int16_t const&>()); } }
TEST_F(BinaryReaderWriterTest, astringTest) { std::vector<asd::astring> orig = { asd::ToAString(L"これは"), asd::ToAString(L"テスト"), asd::ToAString(L"です") }; for (auto const& e : orig) { writer.Push(e); } WriteOut(); ReadIn(); for (auto const e : orig) { ASSERT_FALSE(reader.IsEmpty()); EXPECT_TRUE(e == reader.Get<asd::astring>()); } }
int main() { ofstream outfile("output.txt"); if(!outfile) { cout << "File generation failed"; } else { Heap *heap = new Heap; Set *set = new Set; heap->size = 0; ReadIn(heap); cout <<"\n"; initializeSet(heap->nV, set); Kruskal(heap->nV, set, heap->nE, heap,outfile); } outfile.close(); }
TEST_F(BinaryReaderWriterTest, acharptrTest) { std::vector<asd::astring> source = { asd::ToAString(L"これも"), asd::ToAString(L"テスト"), asd::ToAString(L"です") }; std::vector<asd::achar const*> orig; std::transform(source.begin(), source.end(), std::back_inserter(orig), [](asd::astring const &s){return s.c_str();}); for (auto const e : orig) { writer.Push(e); } WriteOut(); ReadIn(); for (auto const e : orig) { ASSERT_FALSE(reader.IsEmpty()); EXPECT_EQ(asd::ToUtf8String(e), asd::ToUtf8String(reader.Get<asd::achar*>())); } }
/* 并返回TRUE;如无此元素,则返回FALSE */ *p=L; while(*p) { *q=(*p)->next; if(*q&&!strcmp((*q)->data.name,name)) /* 找到该姓名 */ return TRUE; *p=*q; } return FALSE; } Status DeleteElemNum(LinkList L,long num) { /* 删除表中学号为num的元素,并返回TRUE;如无此元素,则返回FALSE */ LinkList p,q; if(FindFromNum(L,num,&p,&q)) /* 找到此结点,且q指向其,p指向其前驱 */ { p->next=q->next; free(q); return TRUE; } return FALSE; } Status DeleteElemName(LinkList L,char name[]) { /* 删除表中姓名为name的元素,并返回TRUE;如无此元素,则返回FALSE */ LinkList p,q; if(FindFromName(L,name,&p,&q)) /* 找到此结点,且q指向其,p指向其前驱 */ { p->next=q->next; free(q); return TRUE; } return FALSE; } void Modify(ElemType *e) { /* 修改结点内容 */ char s[80]; Print(*e); /* 显示原内容 */ printf("请输入待修改项的内容,不修改的项按回车键保持原值:\n"); printf("请输入姓名(<=%d个字符): ",NAMELEN); gets(s); if(strlen(s)) strcpy(e->name,s); printf("请输入学号: "); gets(s); if(strlen(s)) e->num=atol(s); printf("请输入性别(m:男 f:女): "); gets(s); if(strlen(s)) e->sex=s[0]; printf("请输入年龄: "); gets(s); if(strlen(s)) e->age=atoi(s); printf("请输入班级(<=%d个字符): ",CLASSLEN); gets(s); if(strlen(s)) strcpy(e->Class,s); printf("请输入健康状况(0:%s 1:%s 2:%s):",sta[0],sta[1],sta[2]); gets(s); if(strlen(s)) e->health=atoi(s); /* 修改完毕 */ } #define N 4 /* student记录的个数 */ void main() { struct stud student[N]={{"王小林",790631,'m',18,"计91",0}, {"陈红",790632,'f',20,"计91",1}, {"刘建平",790633,'m',21,"计91",0}, {"张立立",790634,'m',17,"计91",2}}; /* 表的初始记录 */ int i,j,flag=1; long num; char filename[13],name[NAMELEN+1]; ElemType e; LinkList T,p,q; InitList(&T); /* 初始化链表 */ while(flag) { printf("1:将结构体数组student中的记录按学号非降序插入链表\n"); printf("2:将文件中的记录按学号非降序插入链表\n"); printf("3:键盘输入新记录,并将其按学号非降序插入链表\n"); printf("4:删除链表中第一个有给定学号的记录\n"); printf("5:删除链表中第一个有给定姓名的记录\n"); printf("6:修改链表中第一个有给定学号的记录\n"); printf("7:修改链表中第一个有给定姓名的记录\n"); printf("8:查找链表中第一个有给定学号的记录\n"); printf("9:查找链表中第一个有给定姓名的记录\n"); printf("10:显示所有记录 11:将链表中的所有记录存入文件 12:结束\n"); printf("请选择操作命令: "); scanf("%d",&i); switch(i) { case 1: for(j=0;j<N;j++) InsertAscend(T,student[j]); break; case 2: printf("请输入文件名: "); scanf("%s",filename); if((fp=fopen(filename,"rb"))==NULL) printf("打开文件失败!\n"); else { while(ReadFromFile(&e)) InsertAscend(T,e); fclose(fp); } break; case 3: ReadIn(&e); InsertAscend(T,e); break; case 4: printf("请输入待删除记录的学号: "); scanf("%ld",&num); if(!DeleteElemNum(T,num)) printf("没有学号为%ld的记录\n",num); break; case 5: printf("请输入待删除记录的姓名: "); scanf("%s",name); if(!DeleteElemName(T,name)) printf("没有姓名为%s的记录\n",name); break; case 6: printf("请输入待修改记录的学号: "); scanf("%ld%*c",&num); /* %*c吃掉回车符 */ if(!FindFromNum(T,num,&p,&q)) printf("没有学号为%ld的记录\n",num); else { Modify(&q->data); if(q->data.num!=num) /* 学号被修改 */ { p->next=q->next; /* 把q所指的结点从L中删除 */ InsertAscend(T,q->data); /* 把元素插入L */ free(q); /* 删除q */ } } break; case 7: printf("请输入待修改记录的姓名: "); scanf("%s%*c",name); /* %*c吃掉回车符 */ if(!FindFromName(T,name,&p,&q)) printf("没有姓名为%s的记录\n",name); else { num=q->data.num; /* 学号存入num */ Modify(&q->data); if(q->data.num!=num) /* 学号被修改 */ { p->next=q->next; /* 把q所指的结点从L中删除 */ InsertAscend(T,q->data); /* 把元素插入L */ free(q); /* 删除q */ } } break; case 8: printf("请输入待查找记录的学号: "); scanf("%ld",&num); if(!FindFromNum(T,num,&p,&q)) printf("没有学号为%ld的记录\n",num); else Print(q->data); break; case 9: printf("请输入待查找记录的姓名: "); scanf("%s",name); if(!FindFromName(T,name,&p,&q)) printf("没有姓名为%s的记录\n",name); else Print(q->data); break; case 10:printf(" 姓名 学号 性别 年龄 班级 健康状况\n"); ListTraverse(T,Print); break; case 11:printf("请输入文件名: "); scanf("%s",filename); if((fp=fopen(filename,"wb"))==NULL) printf("打开文件失败!\n"); else ListTraverse(T,WriteToFile); fclose(fp); break; case 12:flag=0; } } }
TEST_F(BinaryReaderWriterTest, mixedTypeRefTest) { int32_t i = 0x1234ABCD; int16_t sh = 0x1234; int8_t c = 0x12; asd::astring astr(asd::ToAString(L"これはテストです")); std::string str("This is a test"); // asd::achar* achs; asd::Vector3DF v3f = { 1.0f, 2.0f, 3.0f }; asd::Matrix44 m44; writer.Reserve(42); EXPECT_TRUE(writer.Get().capacity() >= 42); for (int j = 0; j < 4; j++) { for (int i = 0; i < 4; i++) { m44.Values[j][i] = i * j; } } writer.Push(i); writer.Push(sh); writer.Push(c); writer.Push(astr); // writer.Push(astr.c_str()); writer.Push(str); writer.Push(42.0f); writer.Push(v3f); writer.Push(m44); WriteOut(); ReadIn(); i = reader.Get<int32_t const&>(); EXPECT_TRUE(i == 0x1234ABCD); sh = reader.Get<int16_t const&>(); EXPECT_TRUE(sh == 0x1234); c = reader.Get<int8_t const&>(); EXPECT_TRUE(c == 0x12); astr = reader.Get<asd::astring>(); EXPECT_TRUE(astr == asd::ToAString(L"これはテストです")); // achs = reader.Get<asd::achar*>(); // EXPECT_TRUE(asd::astring(achs) == asd::ToAString(L"これはテストです")); str = reader.Get<std::string>(); EXPECT_TRUE(str == std::string("This is a test")); EXPECT_TRUE(reader.Get<float const&>() == 42.0f); v3f = reader.Get<asd::Vector3DF>(); EXPECT_TRUE(v3f.X == 1.0f && v3f.Y == 2.0f && v3f.Z == 3.0f); m44 = reader.Get<asd::Matrix44>(); for (int j = 0; j < 4; j++) { for (int i = 0; i < 4; i++) { EXPECT_TRUE(m44.Values[j][i] == i * j); } } }