void EndSW(void) /* switch文の終了 */ { CSentry *p; for (p = SWtbl[SWTptr].CTptr; p < CaseP; p++) { /* 分岐命令の生成 */ Pout(COPY); Cout(PUSHI, p->label); Pout(COMP); Cout(BNE, PC()+3); Pout(REMOVE); Cout(JUMP, p->addr); } Pout(REMOVE); if (SWtbl[SWTptr].DefltAddr > 0) /* defaultラベルが定義? */ Cout(JUMP, SWtbl[SWTptr].DefltAddr); /* そこへのジャンプ命令 */ CaseP = SWtbl[SWTptr--].CTptr; /* ラベル表のポインタを */ } /* 戻す */
void EndInputRecording(HLState* state){ if(state->recordingHandle){ close(state->recordingHandle); } Cout("Stopped recording of index %d", state->recordingIndex); state->recordingIndex = 0; }
theLoop::~theLoop() { AcceptedSocket *nextsck = AcceptedSocketsS; while(nextsck != NULL) { AcceptedSocket *cursck = nextsck; nextsck = cursck->next; #ifdef _WIN32 shutdown(cursck->s, SD_SEND); closesocket(cursck->s); #else shutdown(cursck->s, SHUT_RDWR); close(cursck->s); #endif delete cursck; } AcceptedSocketsS = NULL; AcceptedSocketsE = NULL; #ifdef _WIN32 DeleteCriticalSection(&csAcceptQueue); #else pthread_mutex_destroy(&mtxAcceptQueue); #endif Cout("MainLoop terminated."); }
void EndInputPlayback(HLState* state){ if(state->playbackHandle){ close(state->playbackHandle); } Cout("Stopped playback of index %d", state->playbackIndex); state->playbackIndex = 0; }
File ReadEntireFile(std::string filename, B32 ignoreFailure) { File result = {}; struct stat statBuffer; HANDLE fileDescriptor = open(filename.c_str(), O_RDONLY); if(fileDescriptor != -1) { result.size = GetFileSize(filename, fileDescriptor, True, ignoreFailure); if(result.size) { Cout("File opened: \"%s\"; Size: %lu", filename.c_str(), result.size); result.data = mmap(NULL, result.size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fileDescriptor, 0); if(result.data != MAP_FAILED) { U32 bytesRead = read(fileDescriptor, result.data, result.size); if(bytesRead != result.size) { Cerr("File allocation failed: File: \"%s\"; Size %lu", filename.c_str(), result.size); munmap(result.data, result.size); result.data = NULL; result.size = 0; } } else { if(!ignoreFailure) { Cerr("File request allocation failed: File \"%s\"; Size %lu", filename.c_str(), result.size); } } } else { if(!ignoreFailure) { Cerr("File request failed with size of 0; File: \"%s\"", filename.c_str()); } } close(fileDescriptor); } return result; }
void alu(SD(sd), const Signals& A, const Signals& B, const Signal& Cin, const Signal& Ainvert, const Signal& Binvert, const Signal& Unsgn, const Signals& Op, const Signals& Res, const Signal& C, const Signal& V) { Module((sd, "32 Bit ALU"), (A,B,Cin,Ainvert,Binvert,Unsgn,Op), (Res,C,V) ); Signal Cout(NUM_BITS); Signal lessIn; Signal lessOut; Signal notV; Signal notMSB; Signal notUnsgn; Signal lessJunk(NUM_BITS-1); Signal set; Signal setIntrm(3); Signal Prod1; Signal Prod2; oneBitALU(SD(sd, "1d"), A[0], B[0], Cin, lessIn, Ainvert, Binvert, Op, Res[0], Cout[0], lessJunk[0]); for (int i = 1; i < NUM_BITS-1; ++i) oneBitALU(SD(sd,"1d"), A[i], B[i], Cout[i-1], Zero, Ainvert, Binvert, Op, Res[i], Cout[i], lessJunk[i]); oneBitALU(SD(sd,"1d"), A[NUM_BITS-1], B[NUM_BITS-1], Cout[NUM_BITS-2], Zero, Ainvert, Binvert, Op, Res[NUM_BITS-1], C, lessOut); Not(SD(sd, "1d"), V, notV); Not(SD(sd, "1d"), Res[NUM_BITS-1], notMSB); Not(SD(sd, "1d"), Unsgn, notUnsgn); And(SD(sd, "1d"), (notUnsgn, notV, Res[NUM_BITS-1]), setIntrm[0]); And(SD(sd, "1d"), (notUnsgn, V, notMSB), setIntrm[1]); And(SD(sd, "1d"), (Unsgn, V), setIntrm[2]); Or(SD(sd, "1d"), setIntrm, set); And(SD(sd, "1d"), (set, lessOut), lessIn); Iand(SD(sd, "1d"), (Res[NUM_BITS-1]), (A[NUM_BITS-1],B[NUM_BITS-1]), Prod1); Iand(SD(sd, "1d"), (A[NUM_BITS-1], B[NUM_BITS-1]), (Res[NUM_BITS-1]), Prod2); Or(SD(sd, "1d"), (Prod1, Prod2), V); }
BOOL WINAPI SkylarkApp::CtrlCHandlerRoutine(__in DWORD dwCtrlType) { LOG("Ctrl+C handler"); TheApp().quit = true; Cout() << "Ctrl + C\n"; TcpSocket h; h.Connect("127.0.0.1", TheApp().port); h.Put("quit"); return TRUE; }
void BeginInputPlayback(HLState* state, U32 playbackIndex){ if(!state->playbackIndex && !state->playbackHandle){ state->playbackIndex = playbackIndex; char* filename = RECORDED_AUTON_FILENAME; state->playbackHandle = open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO); Cout("Playing back: [%s] from index %d", filename, playbackIndex); } }
void BeginInputRecording(HLState* state, U32 recordingIndex){ if(!state->recordingIndex && !state->recordingHandle){ state->recordingIndex = recordingIndex; char* filename = RECORDED_AUTON_FILENAME; state->recordingHandle = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); Cout("Recording: [%s] from index %d", filename, recordingIndex); } }
void EndSW(void) { CSentry *p; for (p = SWtbl[SWTptr].CTptr; p < CaseP; p++) { Pout(COPY); Cout(PUSHI, p->label); Pout(COMP); Cout(BNE, PC() + 3); Pout(REMOVE); Cout(JUMP, p->addr); } Pout(REMOVE); if (SWtbl[SWTptr].DefltAddr > 0) { Cout(JUMP, SWtbl[SWTptr].DefltAddr); } CaseP = SWtbl[SWTptr--].CTptr; }
void PosOverrunTest() { String tmpfile = GetTempFileName("pos"); FileOut fo; if(!fo.Open(tmpfile)) { Cout() << "PosOverrunTest: error creating file " << tmpfile << "\n"; return; } for(int i = 0; i < 0x10000; i++) fo.PutIW(i); int64 size = fo.GetSize(); fo.Close(); if(fo.IsError() || size != 0x20000) { Cout() << "PosOverrunTest generator error, file " << tmpfile << "\n"; return; } FileIn fi; fi.SetBufferSize(4096); if(!fi.Open(tmpfile)) { Cout() << "PosOverrunTest: error reopening temporary file " << tmpfile << "\n"; return; } for(int i = 0; i < 4096; i++) fi.Get(); char buffer[32]; fi.GetAll(buffer, 32); bool ok = true; for(int i = 0; i < 16; i++) { int strmval = PeekIW(buffer + 2 * i); int expect = 2048 + i; if(strmval != expect) { Cout() << "PosOverrunTest: " << FormatIntHex(expect, 4) << " expected, " << FormatIntHex(strmval, 4) << " found\n"; ok = false; } } if(ok) Cout() << "PosOverrunTest: finished without errors\n"; }
void DisplayCanvas::Render() { DisplayCards(); //Image[i] = //GLuint OneImage = LoadImageFile(string("./Files/AllCards/Ascending/C41.png")); //cout<<" While OneImage has "<<OneImage<<endl; //DisplaySinglePhoto(0,0,OneImage); glPushMatrix(); ostringstream Info; if(ActiveCard>-1) Info<<" Selected Card :- "<<ActiveCard+1; else Info<<"Press 1 through 9 to select corresponding card "; //glColor3f(0.0,0.8,1.0); Cout(const_cast<char*>(Info.str().c_str()),-.8,0,0); //Printing function glPopMatrix(); }
void classUsers::RemUser(User * u) { if(u->prev == NULL) { if(u->next == NULL) { llist = NULL; elist = NULL; } else { u->next->prev = NULL; llist = u->next; } } else if(u->next == NULL) { u->prev->next = NULL; elist = u->prev; } else { u->prev->next = u->next; u->next->prev = u->prev; } #ifdef _DEBUG int iret = sprintf(msg, "# User %s removed from linked list.", u->sNick); if(CheckSprintf(iret, 1024, "classUsers::RemUser") == true) { Cout(msg); } #endif }
void StreamTest() { FileIn in("d:/chips.cpp"); FileOut out("d:/chips1.cpp"); for(;;) { int c = in.Get(); if(c < 0) break; out.Put(c); } in.Seek(300); out.Seek(300); for(int i = 0; i < 5000; i++) out.Put(in.Get()); out.SetBufferSize(8); out.Seek(0); LOG("================================================"); StringStream ss(LoadFile("d:/chips.cpp")); int nn = 0; dword style = 0; for(;;) { if(++nn % 1000 == 0) Cout() << "ops: " << nn << ", len: " << ss.GetSize() << ", buffersize: " << out.GetBufferSize() << "\n"; if(ss.GetSize() > 256*1024) { int sz = (rand() % 1000) * 100; ss.SetSize(sz); out.SetSize(sz); LOG("Adjusted size: " << ss.GetSize()); } if(ss.GetSize() != out.GetSize()) { Panic("SIZE MISMATCH!"); return; } if((rand() & 255) == 0) { int64 p = out.GetPos(); out.Seek(0); if(ss.GetResult() != LoadStream(out)) { out.Seek(0); SaveFile("d:/f1.txt", LoadStream(out)); SaveFile("d:/f2.txt", ss.GetResult()); Panic("CONTENT INEQUAL!"); return; } out.Seek(p); } int spos = rand() % (int)ss.GetSize(); int ssize = rand() % (out.GetBufferSize() * 7); int tpos = MAKELONG(rand(), rand()) % (int)ss.GetSize(); if((rand() & 3) == 0) tpos = minmax<int>(spos - (rand() & 63) + 32, 0, (int)out.GetSize()); if((rand() & 3) == 0) ssize = rand() % (3 * out.GetBufferSize()); if((rand() & 4091) == 0) { style++; Cout() << "MODE: " << style << "\n"; } LOG("---------------------"); LOG("spos: " << spos << " ssize: " << ssize << " tpos: " << tpos << " style: " << style); // DUMP(ss.GetSize()); // DUMP(out.GetSize()); String a = Copy(out, spos, ssize, tpos, style); String b = Copy(ss, spos, ssize, tpos, style); // DUMP(ss.GetSize()); // DUMP(out.GetSize()); if((rand() & 1023) == 0) out.SetBufferSize((rand() & 127) + 2); if(a != b) { SaveFile("d:/f1c.txt", a); SaveFile("d:/f2c.txt", b); out.Seek(0); SaveFile("d:/f1.txt", LoadStream(out)); SaveFile("d:/f2.txt", ss.GetResult()); DUMP(ss.GetSize()); Panic("INEQUAL READ IN COPY!"); return; } } }
void SkylarkApp::Run() { // DisableHUP(); if(static_dir.GetCount() == 0) static_dir = root + "/static"; SqlSession::PerThread(); SqlId::UseQuotes(); FinalizeViews(); #ifdef PLATFORM_WIN32 SetConsoleCtrlHandler(CtrlCHandlerRoutine, true); #endif main_pid = getpid(); quit = false; IpAddrInfo ipinfo; ipinfo.Execute(ip, port, IpAddrInfo::FAMILY_IPV4); // addrinfo *addr = ipinfo.GetResult(); #ifdef _DEBUG int qq = 0; for(;;) { if(server.Listen(ipinfo, port, 5, false, true)) break; Cout() << "Trying to start listening (other process using the same port?) " << ++qq << "\n"; Sleep(1000); } #else if(!server.Listen(ipinfo, port, 5, false, true)) { SKYLARKLOG("Cannot open server socket for listening!"); Exit(1); } #endif SKYLARKLOG("Starting Skylark, current static path: " << path); #ifdef PLATFORM_POSIX struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SignalHandler; sigaction(SIGUSR1, &sa, NULL); if(prefork) { sigaction(SIGTERM, &sa, NULL); sigaction(SIGINT, &sa, NULL); sigaction(SIGHUP, &sa, NULL); sigaction(SIGALRM, &sa, NULL); // EnableHUP(); while(!quit) { while(child_pid.GetCount() < prefork && !quit) { pid_t p = fork(); if(p == 0) { Main(); return; } else if(p > 0) child_pid.Add(p); else { // "cant create new process" Broadcast(SIGINT); abort(); } } int status = 0; pid_t p = wait(&status); if(p > 0) { int q = FindIndex(child_pid, p); if(q >= 0) child_pid.Remove(q); } } Broadcast(SIGTERM); int status = 0; for(int i = 0; i < child_pid.GetCount(); i++) waitpid(child_pid[i], &status, 0); // "server stopped"; } else #endif Main(); SKYLARKLOG("ExitSkylark"); }
BOOL CALLBACK DlgConsoleProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_INITDIALOG: hDialogHwnd = hwnd; RegisterHotKey(hwnd, TOGGLE, MOD_CONTROL | MOD_ALT, 'Z'); GetAllWindow(); Cout("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDOK: CHAR text[4068], list[4068]; Clear(); getInput(text); //console(text); //UpdateConsole(); WindowsList.getSimilarIdList(text, list); // Cout(list); UpdateConsole(); break; } break; case WM_HOTKEY: //char text[50]; //wsprintf(text, "wParam: %x lParam:%x", wParam, lParam); //MessageBox(hwnd, text, NULL, MB_OK); switch(wParam) { case TOGGLE: if (flag) { ShowWindow(hDialogHwnd, SW_HIDE); flag = 0; }else{ ShowWindow(hDialogHwnd, SW_SHOW); SetFocus(GetDlgItem(hDialogHwnd, IDC_EDIT_LINE)); flag = 1; } break; } break; case WM_MOUSEMOVE: echo("hello key down"); break; case WM_SETFOCUS: // MessageBox(hwnd, (LPCSTR)"WM_SETFOCUS", NULL, MB_OK); break; case WM_CLOSE: EndDialog(hwnd, 0); break; case WM_DESTROY: FreeLibrary(hRichEdit); PostQuitMessage(0); break; default: return DefWindowProc(hwnd, Message, wParam, lParam); } return TRUE; }
void Puts(const char *s) { if(!SilentMode) Cout() << s; }