//--------------------------------------------------------------------------- WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { if(CONSOLE) OpenConsole(); try { Application->Initialize(); Application->CreateForm(__classid(TMainCaptureForm), &MainCaptureForm); Application->Run(); } catch (Exception &exception) { Application->ShowException(&exception); } catch (...) { try { throw Exception(""); } catch (Exception &exception) { Application->ShowException(&exception); } } if(CONSOLE) CloseConsole(); return 0; }
HWND Create( int nCmdShow, int w, int h ) { RECT rc; // Calculate size of window based on desired client window size rc.left = 0; rc.top = 0; rc.right = w; rc.bottom = h; AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE ); HWND hwnd = CreateWindow(g_szAppName, g_szAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right-rc.left, rc.bottom-rc.top, NULL, NULL, g_hInstance, NULL); if (hwnd == NULL) return hwnd; ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); OpenConsole(); return hwnd; }
void CLogManager::LogInit(char* filename,int FileMode,int ConsoleMode,int OutputMode) { if(FileMode==LOGFILE) { strcpy_s(LogFileName,filename); OpenFile(); } if(ConsoleMode==CONSOLE) OpenConsole(); }
void Init() { OpenConsole(); std::cout << "[SNESBot] Opened stdout display." << std::endl; std::cout << "[SNESBot] Initializing SNESBot.." << std::endl; current_mode = new EventMode(); //disable sound (due to segfaults + speedup) Settings.SA1 = false; }
/*ARGSUSED*/ static void InsertSelection(Widget w, XtPointer client_data, Atom *selection, Atom *type, XtPointer value, unsigned long *length, int *format) { if (*type != XT_CONVERT_FAIL) TextInsert (text, (char *) value, *length); XtOwnSelection(top, mit_console, CurrentTime, ConvertSelection, LoseSelection, NULL); OpenConsole (); }
void CApplication::ToggleConsole() { if (!Get()) return; CConsole* pConsole = Get()->GetConsole(); if (IsConsoleOpen()) CloseConsole(); else OpenConsole(); }
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: //这里分成两种实行 OpenConsole(); CheckAllHookEntry(); #ifndef _HARDBREAK_ //修改指令法 SetAllHook(); #else //内存异常法 //#ifndef _OUT RegVEH2(); //#else // InitDynamicHook(); //#endif //硬件断点法 // RegVEH(); // SetMainThreadHardBreakPoint(); //动态内存法 // InitDynamicHook(); #endif //这里使用卸除然后复制的办法隐藏dll,因此不调用HideDLL //具体见wowhack工程 // HideDLL( (HMODULE)hModule ); // printf("hModule=%x\n",hModule); // 不是使用HideDLL,这里要先保存_crtheap内容,因为在FreeLibrary后他被释放了 // 这里提前保存它,然后在回来开始调用后重新分配 CopyHeapToLauncher(); break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: #ifndef _HARDBREAK_ ClearAllHook(); #else //不卸载,因为隐藏dll个时要卸载这个dll,随后代码会被复制回来 //因此这里不卸载VEH // UnregVEH(); #endif // CloseConsole(); break; } return TRUE; }
STDMETHODIMP CConsoleService::WriteLine(BSTR bstr) { CComPtr<IFormManager> pFormManager; RETURN_IF_FAILED(GetFormManager(&pFormManager)); RETURN_IF_FAILED(OpenConsole()); CComPtr<IControl> pConsoleForm; RETURN_IF_FAILED(pFormManager->FindForm(CONTROL_LOG, &pConsoleForm)); CComQIPtr<ILogFormView> pLogFormView = pConsoleForm; ATLENSURE(pLogFormView); RETURN_IF_FAILED(pLogFormView->WriteLine(bstr)); return S_OK; }
void Monitor_Start(RingBuffer *inputBuffer) { dGuard(inputBuffer == NULL); OpenConsole(); PrintLogo(Console); while (1) { uint16_t read = ReadLineInto(inputBuffer); StreamWriter_WriteLine(Console, inputBuffer->Buffer, read); if (!Dispatch(inputBuffer, Console)) break; } StreamWriter_WriteLine(Console, "Bye.", 4); Stream_Close(Console); Console = NULL; }
bool System::GetAppId( ) { wchar_t** args = CommandLineToArgvW( GetCommandLine( ), &m_uNumArgs ); for( uint i = 0; i < m_uNumArgs; i++ ) { m_wsArgs.push_back( args[ i ] ); #ifdef _DEBUG wcout << i << ": " << m_wsArgs[ i ].c_str() << endl; #endif if( !wcscmp( args[ i ], L"bp" ) ) { m_bUseController = true; m_iControllerMode = 0; } if( !wcscmp( args[ i ], L"bp1" ) ) { m_bUseController = true; m_iControllerMode = 1; } } if( m_wsArgs.size( ) > 1 ) { return true; } else { if( MessageBox( 0, L"Launch parameter was not found. Do you want to update executables within this directory?", L"WARNING: Missing parameter/Update", MB_ICONINFORMATION | MB_OKCANCEL | MB_DEFBUTTON2 ) == IDOK ) { #ifndef _DEBUG OpenConsole( ); #endif m_updater->Launch( ); #ifndef _DEBUG FreeConsole( ); #endif } } return false; }
int OpenIO(struct Window *iowin) { if(!(timerport=(struct MsgPort *)CreateMsgPort())) return(FALSE); if(!(timerreq=(struct timerequest *)CreateExtIO(timerport,(LONG)sizeof(struct timerequest)))) return(FALSE); if(OpenTimer(timerreq)) return(FALSE); else timeryes=TRUE; if(!(conwriteport=(struct MsgPort *)CreateMsgPort())) return(FALSE); if(!(conwritereq=(struct IOStdReq *)CreateExtIO(conwriteport,(LONG)sizeof(struct IOStdReq)))) return(FALSE); if(!(conreadport=(struct MsgPort *)CreateMsgPort())) return(FALSE); if(!(conreadreq=(struct IOStdReq *)CreateExtIO(conreadport,(LONG)sizeof(struct IOStdReq)))) return(FALSE); if(OpenConsole(iowin)) return(FALSE); else consoleyes=TRUE; return(TRUE); }
static void inputReady(XtPointer w, int *source, XtInputId *id) { char buffer[1025]; int n; n = read (*source, buffer, sizeof (buffer) - 1); if (n <= 0) { if (app_resources.file && regularFile && n == 0) { if (XPending(XtDisplay(w))) return; sleep(1); return; } fclose (input); XtRemoveInput (*id); /* try to reopen if pipe; this can be caused by syslog restart */ if (app_resources.file && !regularFile && n == 0) { OpenConsole(); } } else { Notify(); buffer[n] = '\0'; if (app_resources.stripNonprint) { stripNonprint (buffer); n = strlen (buffer); } TextAppend ((Widget) text, buffer, n); } }
void Log::AddOutput(int output, std::string path, bool append) { Lock lock(this); if (output & LOG_OUTPUT) { _logoutput = true; } if (output & LOG_FILE) { OpenFile(path, append); } if (output & LOG_CONSOLE) { OpenConsole(); } if (output & LOG_TIME) { _logtime = true; } }
void main(int argc,char *argv[]) { int going=TRUE,forsok=2,car=1,x,connectbps, i, tmp; struct NodeType *nt; char *tmppscreen,commandstring[100], configname[50] = "NiKom:DatoCfg/SerNode.cfg"; FILE *fil; if(argc>1) for(x=1; x<argc; x++) { if(argv[x][0]=='-') { if(argv[x][1]=='G') getty=TRUE; else if(argv[x][1]=='B') gettybps=atoi(&argv[x][2]); else if(argv[x][1]=='C') connectbps = atoi(&argv[x][2]); } else strcpy(configname,argv[x]); } if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0))) cleanup(ERROR,"Kunde inte öppna intuition.library\n"); if(!(UtilityBase=OpenLibrary("utility.library",37L))) cleanup(ERROR,"Kunde inte öppna utility.library\n"); if(!(NiKomBase=OpenLibrary("nikom.library",0L))) cleanup(ERROR,"Kunde inte öppna nikom.library\n"); if(!initnode(NODSER)) cleanup(ERROR,"Kunde inte registrera noden i Servern\n"); if(!(nikomnodeport = CreateMsgPort())) cleanup(ERROR,"Kunde inte skapa NiKomNode-porten"); sprintf(nikomnodeportnamn,"NiKomNode%d",nodnr); nikomnodeport->mp_Node.ln_Name = nikomnodeportnamn; nikomnodeport->mp_Node.ln_Pri = 1; AddPort(nikomnodeport); sprintf(rexxportnamn,"NiKomPreRexx%d",nodnr); if(!(rexxport=(struct MsgPort *)CreateMsgPort())) cleanup(ERROR,"Kunde inte öppna RexxPort\n"); rexxport->mp_Node.ln_Name=rexxportnamn; rexxport->mp_Node.ln_Pri=50; AddPort(rexxport); if(!(RexxSysBase=(struct RsxLib *)OpenLibrary("rexxsyslib.library",0L))) cleanup(ERROR,"Kunde inte öppna rexxsyslib.library\n"); getnodeconfig(configname); if(pubscreen[0]=='-') tmppscreen=NULL; else tmppscreen=pubscreen; if(!(NiKwind=openmywindow(tmppscreen))) cleanup(ERROR,"Kunde inte öppna fönstret\n"); if(getty) dtespeed = gettybps; else dtespeed = highbaud; if(!OpenIO(NiKwind)) cleanup(ERROR,"Couldn't setup IO"); strcpy(Servermem->nodid[nodnr],nodid); conreqtkn(); serreqtkn(); Delay(50); for(;;) { inloggad=-1; Servermem->idletime[nodnr] = time(NULL); Servermem->inloggad[nodnr]=-1; if(getty) Servermem->connectbps[nodnr] = connectbps; else waitconnect(); Servermem->idletime[nodnr] = time(NULL); Servermem->inloggad[nodnr]=-2; /* Sätt till <Uppringd> för att även hantera -getty-fallet */ reloginspec: updateinactive(); Servermem->inne[nodnr].flaggor = Servermem->cfg.defaultflags; if(!getty) Delay(100); Servermem->inne[nodnr].rader=0; Servermem->inne[nodnr].chrset = CHRS_LATIN1; sendfile("NiKom:Texter/Inlogg.txt"); if(Servermem->cfg.ar.preinlogg) sendrexx(Servermem->cfg.ar.preinlogg); car=TRUE; Servermem->inne[nodnr].chrset = 0; memset(commandhistory,0,1000); going=1; while(going && going<=Servermem->cfg.logintries) { putstring("\r\nNamn: ",-1,0); if(getstring(EKO,40,NULL)) { car=FALSE; break; } if(!stricmp(inmat,Servermem->cfg.ny) && !(Servermem->cfg.cfgflags & NICFG_CLOSEDBBS)) { tmp = RegisterNewUser(); if(tmp == 2) { goto panik; } car = tmp ? 0 : 1; going=FALSE; } else if((inloggad=parsenamn(inmat))>=0) { if(readuser(inloggad,&Servermem->inne[nodnr])) { puttekn("Error reading user data.\r\n", -1); goto panik; } // TODO: Extract password loop. Should be identical to in NiKomCon.c forsok=2; while(forsok) { puttekn("\r\nLösen: ",-1); if(Servermem->inne[nodnr].flaggor & STAREKOFLAG) { if(getstring(STAREKO,15,NULL)) { car=FALSE; break; } } else { if(getstring(EJEKO,15,NULL)) { car=FALSE; break; } } if(CheckPassword(inmat, Servermem->inne[nodnr].losen)) { forsok=FALSE; going=FALSE; } else forsok--; } if(going && (Servermem->cfg.logmask & LOG_FAILINLOGG)) { LogEvent(USAGE_LOG, WARN, "Nod %d, %s angivet som namn, fel lösen.", nodnr, getusername(inloggad)); } if(going) going++; } else if(inloggad==-1) puttekn("\r\nHittar ej namnet\r\n",-1); } if(!car) { if(getty) cleanup(OK,""); disconnect(); continue; } if(going) { putstring("\n\n\rTyvärr. Du har försökt maximalt antal gånger att logga in. Kopplar ned.\n\r",-1,0); goto panik; /* Urrk vad fult. :-) */ } Servermem->inloggad[nodnr]=inloggad; Servermem->idletime[nodnr] = time(NULL); if((nt = selectNodeType()) == NULL) { goto panik; } abortinactive(); abortserial(); sprintf(commandstring,"%s -N%d -B%d %s",nt->path,nodnr,dtespeed,configname); CloseConsole(); CloseWindow(NiKwind); NiKwind = NULL; RemPort(nikomnodeport); i = 0; if(Servermem->connectbps[nodnr] > 0) { while(Servermem->info.bps[i] != Servermem->connectbps[nodnr] && Servermem->info.bps[i] > 0 && i<49) i++; if(i<49) { if(Servermem->info.bps[i] == Servermem->connectbps[nodnr]) Servermem->info.antbps[i]++; else { Servermem->info.bps[i] = Servermem->connectbps[nodnr]; Servermem->info.antbps[i]++; } } if(!(fil = fopen("NiKom:datocfg/sysinfo.dat","w"))) { /* putstring("Kunde inte spara nya sysinfo.dat..\n",-1,0); */ } if(fwrite((void *)&Servermem->info,sizeof(Servermem->info),1,fil) != 1) { /* putstring("Kunde inte skriva till nya sysinfo.dat....\n",-1,0); */ } fclose(fil); } nodestate = SystemTags(commandstring, SYS_UserShell, TRUE, TAG_DONE); AddPort(nikomnodeport); if(!getty || (nodestate & NIKSTATE_RELOGIN)) { if(!(NiKwind = openmywindow(tmppscreen))) cleanup(ERROR,"Kunde inte öppna fönstret\n"); OpenConsole(NiKwind); } serreqtkn(); if(nodestate & NIKSTATE_RELOGIN) goto reloginspec; panik: Delay(hangupdelay); if(getty) cleanup(OK,""); disconnect(); } }
int main(int argc, char **argv) { unsigned long valuemask; /* mask for create windows */ XSetWindowAttributes attributes; /* attributes for create windows */ void InternUsefulAtoms(void); void InitVariables(void); int i, len; extern int x_fd; char *display_string; char message[255]; Bool single = False; Bool option_error = FALSE; MenuRoot *mr; g_argv = argv; g_argc = argc; OpenConsole(); DBUG("main", "Entered, about to parse args"); for (i = 1; i < argc; i++) { if (strncasecmp(argv[i], "-debug", 6) == 0) { debugging = True; } else if (strncasecmp(argv[i], "-s", 2) == 0) { single = True; } else if (strncasecmp(argv[i], "-d", 2) == 0) { if (++i >= argc) usage(); display_name = argv[i]; } else if (strncasecmp(argv[i], "-f", 2) == 0) { if (++i >= argc) usage(); config_command = (char *) malloc(6 + strlen(argv[i])); strcpy(config_command, "Read "); strcat(config_command, argv[i]); free_config_command = True; } else if (strncasecmp(argv[i], "-cmd", 4) == 0) { if (++i >= argc) usage(); config_command = argv[i]; } else if (strncasecmp(argv[i], "-file", 5) == 0) { if (++i >= argc) usage(); output_file = argv[i]; } else if (strncasecmp(argv[i], "-h", 2) == 0) { usage(); exit(0); } else if (strncasecmp(argv[i], "-blackout", 9) == 0) { Blackout = True; } else if (strncasecmp(argv[i], "-version", 8) == 0) { fvwm_msg(INFO, "main", "Fvwm95 Version %s compiled on %s at %s\n", VERSION, __DATE__, __TIME__); } else { fvwm_msg(ERR, "main", "Unknown option: `%s'\n", argv[i]); option_error = TRUE; } } DBUG("main", "Done parsing args"); if (option_error) { usage(); } DBUG("main", "Installing signal handlers"); newhandler(SIGINT); newhandler(SIGHUP); newhandler(SIGQUIT); newhandler(SIGTERM); signal(SIGUSR1, Restart); signal(SIGPIPE, DeadPipe); ReapChildren(); if (!(dpy = XOpenDisplay(display_name))) { fvwm_msg(ERR, "main", "can't open display %s", XDisplayName(display_name)); exit(1); } Scr.screen = DefaultScreen(dpy); Scr.NumberOfScreens = ScreenCount(dpy); master_pid = getpid(); if (!single) { int myscreen = 0; char *cp; strcpy(message, XDisplayString(dpy)); XCloseDisplay(dpy); for (i = 1; i < Scr.NumberOfScreens; i++) { if (fork() == 0) { myscreen = i; break; } } /* * Truncate the string 'whatever:n.n' to 'whatever:n', * and then append the screen number. */ cp = strchr(message, ':'); if (cp != NULL) { cp = strchr(cp, '.'); if (cp != NULL) *cp = '\0'; /* truncate at display part */ } sprintf(message + strlen(message), ".%d", myscreen); dpy = XOpenDisplay(message); Scr.screen = myscreen; Scr.NumberOfScreens = ScreenCount(dpy); } x_fd = XConnectionNumber(dpy); fd_width = GetFdWidth(); if (fcntl(x_fd, F_SETFD, 1) == -1) { fvwm_msg(ERR, "main", "close-on-exec failed"); exit(1); } /* Add a DISPLAY entry to the environment, in case we were started * with fvwm -display term:0.0 */ len = strlen(XDisplayString(dpy)); display_string = safemalloc(len + 10); sprintf(display_string, "DISPLAY=%s", XDisplayString(dpy)); putenv(display_string); /* Add a HOSTDISPLAY environment variable, which is the same as * DISPLAY, unless display = :0.0 or unix:0.0, in which case the full * host name will be used for ease in networking . */ /* Note: Can't free the rdisplay_string after putenv, because it * becomes part of the environment! */ if (strncmp(display_string, "DISPLAY=:", 9) == 0) { char client[MAXHOSTNAME], *rdisplay_string; mygethostname(client, MAXHOSTNAME); rdisplay_string = safemalloc(len + 14 + strlen(client)); sprintf(rdisplay_string, "HOSTDISPLAY=%s:%s", client, &display_string[9]); putenv(rdisplay_string); } else if (strncmp(display_string, "DISPLAY=unix:", 13) == 0) { char client[MAXHOSTNAME], *rdisplay_string; mygethostname(client, MAXHOSTNAME); rdisplay_string = safemalloc(len + 14 + strlen(client)); sprintf(rdisplay_string, "HOSTDISPLAY=%s:%s", client, &display_string[13]); putenv(rdisplay_string); } else { char *rdisplay_string; rdisplay_string = safemalloc(len + 14); sprintf(rdisplay_string, "HOSTDISPLAY=%s", XDisplayString(dpy)); putenv(rdisplay_string); } Scr.Root = RootWindow(dpy, Scr.screen); if (Scr.Root == None) { fvwm_msg(ERR, "main", "Screen %d is not a valid screen", (char *) Scr.screen); exit(1); } #ifdef SHAPE ShapesSupported = XShapeQueryExtension(dpy, &ShapeEventBase, &ShapeErrorBase); #endif /* SHAPE */ InternUsefulAtoms(); /* Make sure property priority colors is empty */ XChangeProperty(dpy, Scr.Root, _XA_MIT_PRIORITY_COLORS, XA_CARDINAL, 32, PropModeReplace, NULL, 0); XSetErrorHandler((XErrorHandler) CatchRedirectError); XSetIOErrorHandler((XIOErrorHandler) CatchFatal); XSelectInput(dpy, Scr.Root, LeaveWindowMask | EnterWindowMask | PropertyChangeMask | SubstructureRedirectMask | KeyPressMask | SubstructureNotifyMask | ButtonPressMask | ButtonReleaseMask); XSync(dpy, 0); XSetErrorHandler((XErrorHandler) FvwmErrorHandler); BlackoutScreen(); CreateCursors(); InitVariables(); InitEventHandlerJumpTable(); initModules(); InitPictureCMap(dpy, Scr.Root); /* for the pixmap cache... */ Scr.gray_bitmap = XCreateBitmapFromData(dpy, Scr.Root, g_bits, g_width, g_height); DBUG("main", "Setting up rc file defaults..."); SetRCDefaults(); DBUG("main", "Running config_command..."); ExecuteFunction(config_command, NULL, &Event, C_ROOT, -1); DBUG("main", "Done running config_command"); /* CaptureAllWindows(); MakeMenus(); */ #if 0 /* this seems to cause problems for FvwmCpp/M4 startup actually */ /* if not a direct 'Read', we'll capture all windows here, in case cmd fails we'll still have defaults */ if (strncasecmp(config_command, "Read", 4) != 0 && strncasecmp(config_command, "PipeRead", 8) != 0) { /* so if cmd (FvwmM4/Cpp most likely) fails, we can still have borders & stuff... */ StartupStuff(); } #endif /* 0 */ if (free_config_command) { free(config_command); } if (Scr.d_depth < 2) { Scr.gray_pixmap = XCreatePixmapFromBitmapData(dpy, Scr.Root, g_bits, g_width, g_height, Scr.WinColors.fore, Scr.WinColors.back, Scr.d_depth); Scr.light_gray_pixmap = XCreatePixmapFromBitmapData(dpy, Scr.Root, l_g_bits, l_g_width, l_g_height, Scr.WinColors.fore, Scr.WinColors.back, Scr.d_depth); } /* create a window which will accept the keyboard focus when no other windows have it */ attributes.event_mask = KeyPressMask | FocusChangeMask; attributes.override_redirect = True; Scr.NoFocusWin = XCreateWindow(dpy, Scr.Root, -10, -10, 10, 10, 0, 0, InputOnly, CopyFromParent, CWEventMask | CWOverrideRedirect, &attributes); XMapWindow(dpy, Scr.NoFocusWin); SetMWM_INFO(Scr.NoFocusWin); XSetInputFocus(dpy, Scr.NoFocusWin, RevertToParent, CurrentTime); XSync(dpy, 0); if (debugging) XSynchronize(dpy, 1); Scr.SizeStringWidth = XTextWidth(Scr.StdFont.font, " +8888 x +8888 ", 15); attributes.border_pixel = Scr.WinColors.fore; attributes.background_pixel = Scr.WinColors.back; attributes.bit_gravity = NorthWestGravity; attributes.save_under = True; valuemask = (CWBorderPixel | CWBackPixel | CWBitGravity | CWSaveUnder); /* create the window for coordinates */ Scr.SizeWindow = XCreateWindow(dpy, Scr.Root, Scr.MyDisplayWidth / 2 - (Scr.SizeStringWidth + SIZE_HINDENT * 2) / 2, Scr.MyDisplayHeight / 2 - (Scr.StdFont.height + SIZE_VINDENT * 2) / 2, (unsigned int) (Scr.SizeStringWidth + SIZE_HINDENT * 2), (unsigned int) (Scr.StdFont.height + SIZE_VINDENT * 2), (unsigned int) 0, 0, (unsigned int) CopyFromParent, (Visual *) CopyFromParent, valuemask, &attributes); #ifndef NON_VIRTUAL initPanFrames(); #endif XGrabServer(dpy); #ifndef NON_VIRTUAL checkPanFrames(); #endif XUngrabServer(dpy); UnBlackoutScreen(); DBUG("main", "Entering HandleEvents loop..."); HandleEvents(); DBUG("main", "Back from HandleEvents loop? Exiting..."); return 0; }
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { MSG uMsg; memset(&uMsg,0,sizeof(uMsg)); winClass.lpszClassName = "MY_WINDOWS_CLASS"; winClass.cbSize = sizeof(WNDCLASSEX); winClass.style = CS_HREDRAW | CS_VREDRAW; winClass.lpfnWndProc = WndProc; winClass.hInstance = hInstance; winClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); winClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); winClass.hCursor = LoadCursor(NULL, IDC_ARROW); winClass.lpszMenuName = MAKEINTRESOURCE(IDC_CV); winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winClass.cbClsExtra = 0; winClass.cbWndExtra = 0; if( !RegisterClassEx(&winClass) ) return E_FAIL; GetINIPath(); OpenConsoleWindow = GetPrivateProfileBool("Display", "OpenConsoleWindow", true, IniName); if (OpenConsoleWindow) OpenConsole(); pcejin.aspectRatio = GetPrivateProfileBool("Video", "aspectratio", false, IniName); pcejin.windowSize = GetPrivateProfileInt("Video", "pcejin.windowSize", 1, IniName); WndX = GetPrivateProfileInt("Main", "WndX", 0, IniName); WndY = GetPrivateProfileInt("Main", "WndY", 0, IniName); g_hWnd = CreateWindowEx( NULL, "MY_WINDOWS_CLASS", pcejin.versionName.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, WndX, WndY, 348, 224, NULL, NULL, hInstance, NULL ); if( g_hWnd == NULL ) return E_FAIL; ScaleScreen((float)pcejin.windowSize); soundInit(); LoadIniSettings(); InitSpeedThrottle(); DirectDrawInit(); InitCustomControls(); InitCustomKeys(&CustomKeys); LoadHotkeyConfig(); LoadInputConfig(); DragAcceptFiles(g_hWnd, true); extern void Agg_init(); Agg_init(); if (osd) {delete osd; osd =NULL; } osd = new OSDCLASS(-1); di_init(); DWORD wmTimerRes; TIMECAPS tc; if (timeGetDevCaps(&tc, sizeof(TIMECAPS))== TIMERR_NOERROR) { wmTimerRes = std::min(std::max(tc.wPeriodMin, (UINT)1), tc.wPeriodMax); timeBeginPeriod (wmTimerRes); } else { wmTimerRes = 5; timeBeginPeriod (wmTimerRes); } if (KeyInDelayMSec == 0) { DWORD dwKeyboardDelay; SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &dwKeyboardDelay, 0); KeyInDelayMSec = 250 * (dwKeyboardDelay + 1); } if (KeyInRepeatMSec == 0) { DWORD dwKeyboardSpeed; SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &dwKeyboardSpeed, 0); KeyInRepeatMSec = (int)(1000.0/(((30.0-2.5)/31.0)*dwKeyboardSpeed+2.5)); } if (KeyInRepeatMSec < (int)wmTimerRes) KeyInRepeatMSec = (int)wmTimerRes; if (KeyInDelayMSec < KeyInRepeatMSec) KeyInDelayMSec = KeyInRepeatMSec; hKeyInputTimer = timeSetEvent (KeyInRepeatMSec, 0, KeyInputTimer, 0, TIME_PERIODIC); ShowWindow( g_hWnd, nCmdShow ); UpdateWindow( g_hWnd ); initialize(); if (lpCmdLine[0])ParseCmdLine(lpCmdLine, g_hWnd); while( uMsg.message != WM_QUIT ) { if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) ) { TranslateMessage( &uMsg ); DispatchMessage( &uMsg ); } else { emulate(); render(); } if(!pcejin.started) Sleep(1); } // shutDown(); timeEndPeriod (wmTimerRes); CloseAllToolWindows(); UnregisterClass( "MY_WINDOWS_CLASS", winClass.hInstance ); return uMsg.wParam; }
int main() { OpenConsole(); Screen::setScreenSize(Vector2(1280, 720)); sf::RenderWindow renderWindow(sf::VideoMode(Screen::getScreenSize().x, Screen::getScreenSize().y, 32), "RayMarch Renderer", sf::Style::Titlebar | sf::Style::Close); renderWindow.setActive(); GUI gui = GUI(&renderWindow); renderWindow.resetGLStates(); //Graphics::setImageSize(Vector2(1280, 720)); Graphics::Init(); Camera camera = Camera(Vector3(0, 4, -6), Vector3(0, -3, 6).normalized(), Graphics::getImageSize().x / Graphics::getImageSize().y, PI / 4); int samples = 128; int currentSample = 0; int gridWidth = 4; int gridHeight = 4; int chunkWidth = Graphics::getImageSize().x / gridWidth; int chunkHeight = Graphics::getImageSize().y / gridHeight; int x = ceil((float)gridWidth / 2.0) - 1; int y = ceil((float)gridHeight / 2.0) - 1; Vector2 dir = Vector2(-1, 0); int squaresPassed = 0; int lastSquaresPassed = 0; int distCount = 0; bool willSave = false; bool wasRendering = false; bool rendering = false; bool sDown = false; bool wasSDown = false; double renderStartTime = 0; double renderEndTime = 0; double oldTime = 0; double newTime = 0; clock_t t = clock(); while (renderWindow.isOpen()) { sf::Event windowEvent; while (renderWindow.pollEvent(windowEvent)) { gui.handleEvent(windowEvent); switch (windowEvent.type) { case sf::Event::Closed: renderWindow.close(); break; } } sDown = sf::Keyboard::isKeyPressed(sf::Keyboard::S); rendering = gui.getRendering(); if (gui.getReload()) { // Reload samples = gui.getSamples(); currentSample = 0; gridWidth = gui.getGridSize().x; gridHeight = gui.getGridSize().y; chunkWidth = Graphics::getImageSize().x / gridWidth; chunkHeight = Graphics::getImageSize().y / gridHeight; x = ceil((float)gridWidth / 2.0) - 1; y = ceil((float)gridHeight / 2.0) - 1; dir = Vector2(-1, 0); squaresPassed = 0; lastSquaresPassed = 0; distCount = 0; Graphics::Reload(); camera.setAspect(Graphics::getImageSize().x / Graphics::getImageSize().y); camera.calculateRays(); renderStartTime = (double)(clock() - t) / (double)CLOCKS_PER_SEC; renderEndTime = 0; } if (rendering) { if (samples == 0) { if (squaresPassed < gridWidth * gridHeight) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { rendering = false; renderEndTime = (double)(clock() - t) / (double)CLOCKS_PER_SEC; std::cout << "Render Time: " << renderEndTime - renderStartTime << std::endl; gui.stopRendering(); } Vector2 min = Vector2(x * chunkWidth, y * chunkHeight); Vector2 max = Vector2((x + 1) * chunkWidth, (y + 1) * chunkHeight); Graphics::Render(newTime, min, max, currentSample); std::cout << currentSample << std::endl; x -= gridWidth / 2; y -= gridHeight / 2; if (distCount * 2 == squaresPassed - lastSquaresPassed) { distCount++; lastSquaresPassed = squaresPassed; dir = Vector2(dir.y, -dir.x); } else if (distCount == squaresPassed - lastSquaresPassed) { dir = Vector2(dir.y, -dir.x); } squaresPassed++; x += dir.x; y += dir.y; x += gridWidth / 2; y += gridHeight / 2; } else { x = ceil((float)gridWidth / 2.0) - 1; y = ceil((float)gridHeight / 2.0) - 1; dir = Vector2(-1, 0); squaresPassed = 0; lastSquaresPassed = 0; distCount = 0; currentSample++; } } else { if (squaresPassed < gridWidth * gridHeight) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { rendering = false; renderEndTime = (double)(clock() - t) / (double)CLOCKS_PER_SEC; std::cout << "Render Time: " << renderEndTime - renderStartTime << std::endl; gui.stopRendering(); } if (currentSample < samples) { Vector2 min = Vector2(x * chunkWidth, y * chunkHeight); Vector2 max = Vector2((x + 1) * chunkWidth, (y + 1) * chunkHeight); Graphics::Render(newTime, min, max, currentSample); currentSample++; //std::cout << currentSample << "/" << samples << std::endl; } else { x -= gridWidth / 2; y -= gridHeight / 2; if (distCount * 2 == squaresPassed - lastSquaresPassed) { distCount++; lastSquaresPassed = squaresPassed; dir = Vector2(dir.y, -dir.x); } else if (distCount == squaresPassed - lastSquaresPassed) { dir = Vector2(dir.y, -dir.x); } squaresPassed++; x += dir.x; y += dir.y; x += gridWidth / 2; y += gridHeight / 2; currentSample = 0; } } else { if (willSave) { save(); willSave = false; } rendering = false; renderEndTime = (double)(clock() - t) / (double)CLOCKS_PER_SEC; std::cout << "Render Time: " << renderEndTime - renderStartTime << std::endl; gui.stopRendering(); } } } else { if (sDown && !wasSDown) { save(); } } //*/ gui.update(newTime); renderWindow.clear(); gui.display(renderWindow); renderWindow.display(); wasSDown = sDown; oldTime = newTime; newTime = (double)(clock() - t) / (double)CLOCKS_PER_SEC; Screen::setDeltaTime(newTime - oldTime); } //Graphics::Cleanup(); }
/****************************************************************************** Main - Setup the XConnection,request the window list and loop forever Based on main() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ int main(int argc, char **argv) { char *temp, *s; #ifdef HAVE_SIGACTION struct sigaction sigact; #endif /* Save the program name for error messages and config parsing */ temp = argv[0]; s=strrchr(argv[0], '/'); if (s != NULL) temp = s + 1; /* Setup my name */ Module = safemalloc(strlen(temp)+2); strcpy(Module,"*"); strcat(Module, temp); Clength = strlen(Module); /* Open the console for messages */ OpenConsole(); if((argc != 6)&&(argc != 7)) { fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",Module, VERSION); ConsoleMessage("%s Version %s should only be executed by fvwm!\n",Module, VERSION); exit(1); } if ((argc==7)&&(!strcasecmp(argv[6],"Transient"))) Transient=1; Fvwm_fd[0] = atoi(argv[1]); Fvwm_fd[1] = atoi(argv[2]); #ifdef HAVE_SIGACTION #ifdef SA_INTERRUPT sigact.sa_flags = SA_INTERRUPT; #else sigact.sa_flags = 0; #endif sigemptyset(&sigact.sa_mask); sigact.sa_handler = TerminateHandler; sigaction(SIGPIPE, &sigact, NULL); sigaction(SIGTERM, &sigact, NULL); #else signal(SIGPIPE, TerminateHandler); signal(SIGTERM, TerminateHandler); #ifdef HAVE_SIGINTERRUPT siginterrupt(SIGPIPE, True); siginterrupt(SIGTERM, True); #endif #endif /* Parse the config file */ ParseConfig(); /* Setup the XConnection */ StartMeUp(); XSetErrorHandler(ErrorHandler); InitPictureCMap(dpy, Root); InitArray(&buttons,0,0,win_width, fontheight+6); InitList(&windows); fd_width = GetFdWidth(); /* Request a list of all windows, * wait for ConfigureWindow packets */ SetMessageMask(Fvwm_fd,M_CONFIGURE_WINDOW | M_RES_CLASS | M_RES_NAME | M_ADD_WINDOW | M_DESTROY_WINDOW | M_ICON_NAME | M_DEICONIFY | M_ICONIFY | M_END_WINDOWLIST | M_NEW_DESK | M_NEW_PAGE | M_FOCUS_CHANGE | M_WINDOW_NAME | #ifdef MINI_ICONS M_MINI_ICON | #endif M_STRING); SendFvwmPipe("Send_WindowList",0); /* Recieve all messages from Fvwm */ atexit(ShutMeDown); MainEventLoop(); return 0; }
void Main() { OpenConsole(); printf("meSSL injected!\n"); HookSSL(); }
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { MSG uMsg; memset(&uMsg,0,sizeof(uMsg)); winClass.lpszClassName = "MY_WINDOWS_CLASS"; winClass.cbSize = sizeof(WNDCLASSEX); winClass.style = CS_HREDRAW | CS_VREDRAW; winClass.lpfnWndProc = WndProc; winClass.hInstance = hInstance; winClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); winClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); winClass.hCursor = LoadCursor(NULL, IDC_ARROW); winClass.lpszMenuName = MAKEINTRESOURCE(IDC_CV); winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winClass.cbClsExtra = 0; winClass.cbWndExtra = 0; OpenConsole(); if( !RegisterClassEx(&winClass) ) return E_FAIL; GetINIPath(); LoadSettings(); pcejin.aspectRatio = GetPrivateProfileInt("Video", "aspectratio", 0, IniName); pcejin.windowSize = GetPrivateProfileInt("Video", "pcejin.windowSize", 1, IniName); WndX = GetPrivateProfileInt("Main", "WndX", 0, IniName); WndY = GetPrivateProfileInt("Main", "WndY", 0, IniName); g_hWnd = CreateWindowEx( NULL, "MY_WINDOWS_CLASS", pcejin.versionName.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, WndX, WndY, 256, 232, NULL, NULL, hInstance, NULL ); if( g_hWnd == NULL ) return E_FAIL; ScaleScreen(pcejin.windowSize); soundInit(); LoadIniSettings(); InitSpeedThrottle(); RecentROMs.SetGUI_hWnd(g_hWnd); RecentROMs.SetID(RECENTROM_START); RecentROMs.SetMenuID(ID_FILE_RECENTROM); RecentROMs.SetType("ROM"); RecentROMs.MakeRecentMenu(hInstance); RecentROMs.GetRecentItemsFromIni(IniName, "General"); RecentMovies.SetGUI_hWnd(g_hWnd); RecentMovies.SetID(RECENTMOVIE_START); RecentMovies.SetMenuID(ID_MOVIE_RECENT); RecentMovies.SetType("Movie"); RecentMovies.MakeRecentMenu(hInstance); RecentMovies.GetRecentItemsFromIni(IniName, "General"); RecentLua.SetGUI_hWnd(g_hWnd); RecentLua.SetID(RECENTLUA_START); RecentLua.SetMenuID(ID_LUA_RECENT); RecentLua.SetType("Lua"); RecentLua.MakeRecentMenu(hInstance); RecentLua.GetRecentItemsFromIni(IniName, "General"); DirectDrawInit(); InitCustomControls(); InitCustomKeys(&CustomKeys); LoadHotkeyConfig(); LoadInputConfig(); DragAcceptFiles(g_hWnd, true); extern void Agg_init(); Agg_init(); if (osd) {delete osd; osd =NULL; } osd = new OSDCLASS(-1); di_init(); DWORD wmTimerRes; TIMECAPS tc; if (timeGetDevCaps(&tc, sizeof(TIMECAPS))== TIMERR_NOERROR) { wmTimerRes = std::min(std::max(tc.wPeriodMin, (UINT)1), tc.wPeriodMax); timeBeginPeriod (wmTimerRes); } else { wmTimerRes = 5; timeBeginPeriod (wmTimerRes); } if (KeyInDelayMSec == 0) { DWORD dwKeyboardDelay; SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &dwKeyboardDelay, 0); KeyInDelayMSec = 250 * (dwKeyboardDelay + 1); } if (KeyInRepeatMSec == 0) { DWORD dwKeyboardSpeed; SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &dwKeyboardSpeed, 0); KeyInRepeatMSec = (int)(1000.0/(((30.0-2.5)/31.0)*dwKeyboardSpeed+2.5)); } if (KeyInRepeatMSec < (int)wmTimerRes) KeyInRepeatMSec = (int)wmTimerRes; if (KeyInDelayMSec < KeyInRepeatMSec) KeyInDelayMSec = KeyInRepeatMSec; hKeyInputTimer = timeSetEvent (KeyInRepeatMSec, 0, KeyInputTimer, 0, TIME_PERIODIC); ShowWindow( g_hWnd, nCmdShow ); UpdateWindow( g_hWnd ); initialize(); if (lpCmdLine[0])ParseCmdLine(lpCmdLine, g_hWnd); if (RecentROMs.GetAutoLoad() && (!skipAutoLoadROM)) { ALoad(RecentROMs.GetRecentItem(0).c_str()); } //Intentionally does not prompt for a game if no game specified, user should be forced to autoload roms as well, for this to work properly if (RecentMovies.GetAutoLoad() && (!skipAutoLoadMovie)) { LoadMovie(RecentMovies.GetRecentItem(0).c_str(), 1, false, false); } if (RecentLua.GetAutoLoad() && (!skipAutoLoadLua)) { char temp [1024]; strcpy(temp, RecentLua.GetRecentItem(0).c_str()); HWND hDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_LUA), g_hWnd, (DLGPROC) LuaScriptProc); SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)temp); } while( uMsg.message != WM_QUIT ) { if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) ) { TranslateMessage( &uMsg ); DispatchMessage( &uMsg ); } else { emulate(); render(); } if(!pcejin.started) Sleep(1); } // shutDown(); timeEndPeriod (wmTimerRes); CloseAllToolWindows(); UnregisterClass( "MY_WINDOWS_CLASS", winClass.hInstance ); return uMsg.wParam; }
/****************************************************************************** Main - Setup the XConnection,request the window list and loop forever Based on main() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ int main(int argc, char **argv) { char *temp, *s; /* Save the program name for error messages and config parsing */ temp = argv[0]; s=strrchr(argv[0], '/'); if (s != NULL) temp = s + 1; /* Setup my name */ Module = safemalloc(strlen(temp)+2); strcpy(Module,"*"); strcat(Module, temp); Clength = strlen(Module); /* Open the console for messages */ OpenConsole(); if((argc != 6)&&(argc != 7)) { fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",Module, VERSION); ConsoleMessage("%s Version %s should only be executed by fvwm!\n",Module, VERSION); exit(1); } if ((argc==7)&&(!strcasecmp(argv[6],"Transient"))) Transient=1; Fvwm_fd[0] = atoi(argv[1]); Fvwm_fd[1] = atoi(argv[2]); signal (SIGPIPE, DeadPipe); /* Parse the config file */ ParseConfig(); /* Setup the XConnection */ StartMeUp(); XSetErrorHandler((XErrorHandler) ErrorHandler); InitPictureCMap(dpy, Root); InitArray(&buttons,0,0,win_width, fontheight+6); InitList(&windows); fd_width = GetFdWidth(); /* Request a list of all windows, * wait for ConfigureWindow packets */ SendFvwmPipe("Send_WindowList",0); /* SetMessageMask(Fvwm_fd,M_ADD_WINDOW|M_CONFIGURE_WINDOW| M_DESTROY_WINDOW| M_WINDOW_NAME|M_ICON_NAME|M_DEICONIFY|M_ICONIFY|M_END_WINDOWLIST| M_NEW_DESK| M_NEW_PAGE);*/ /* Recieve all messages from Fvwm */ EndLessLoop(); return 0; }
/*------------------------------------------------------------------------------------ * 函数: start() * * 描述: 应用程序启始例程 **----------------------------------------------------------------------------------*/ void __task start(void * data) { data = data; /* TaskCreate(demo_task, (void *)1, "demo1", NULL, 512, 1, TASK_CREATE_OPT_NONE); TaskCreate(demo_task, (void *)2, "demo2", NULL, 512, 2, TASK_CREATE_OPT_NONE); TaskCreate(demo_task, (void *)3, "demo3", NULL, 512, 3, TASK_CREATE_OPT_NONE); TaskCreate(demo_task, (void *)4, "demo4", NULL, 512, 4, TASK_CREATE_OPT_NONE); TaskCreate(demo_task, (void *)5, "demo5", NULL, 512, 5, TASK_CREATE_OPT_NONE); TaskCreate(demo_task, (void *)6, "demo6", NULL, 512, 6, TASK_CREATE_OPT_NONE); TaskCreate(demo_task, (void *)7, "demo7", NULL, 512, 7, TASK_CREATE_OPT_NONE); TaskCreate(demo_task, (void *)8, "demo8", NULL, 512, 8, TASK_CREATE_OPT_NONE); */ demo_init_gui(); TaskCreate(refresh_task, NULL, "refresh", NULL, 2048, 8, TASK_CREATE_OPT_NONE); OpenConsole(); RegisterSpecialKey('x', move_button); for(;;){ KEYCODE key; char buf[64] = {0, }; key = gui_edit_input(test, buf, 32, 0); /* use superkey alt-x-k to quit! */ switch(key){ case UP: gui_view_move_up(view); break; case DOWN: gui_view_move_down(view); break; case PGUP: gui_view_page_up(view); break; case PGDN: gui_view_page_down(view); break; } switch(buf[0]){ default: break; case 'c': case 'C': color = atoi(&buf[1]); gui_set_widget_color(edit, color); break; case 'b': case 'B': bkcolor = atoi(&buf[1]); gui_set_widget_bkcolor(edit, bkcolor); break; case 's': case 'S': style = STRtoINT16(&buf[1], 0); gui_set_widget_style(edit, style); break; case 'p': case 'P': /* gui_progress_set_value(progress1, atoi(&buf[1])); */ break; case 'a': case 'A': { struct student * t; t = mem_alloc(sizeof(*t)); if(!t) break; sprintf(t->name, "Name"); t->sex = '-'; t->old = 0; sprintf(t->comment, ""); lock_kernel(); t->next = all_students; all_students = t; unlock_kernel(); } break; case 'd': case 'D': /*gui_show_window(window2);*/ input_dialog_method(&abcde, dialog_prepare, dialog_finish, NULL, 1); { static COLOR tmp = 67; gui_desktop_set_color(tmp); tmp += 77; } TaskSleep(10); /*gui_hide_window(window2);*/ break; case 'h': case 'H': gui_hide_window(window3); break; case 'f': case 'F': gui_show_window(window3); break; case 'm': case 'M': while (1) { gui_window_t * w; KEYCODE move; if (buf[0] == 'm') w = window2; else w = window3; move = getkey(); switch (move) { case ESC: goto out_while; case LEFT: gui_window_move(w, -23, 0); break; case RIGHT: gui_window_move(w, 13, 0); break; case UP: gui_window_move(w, 0, -11); break; case DOWN: gui_window_move(w, 0, 23); break; case CTRL_LEFT: gui_window_resize(w, -23, 0); break; case CTRL_RIGHT: gui_window_resize(w, 13, 0); break; case CTRL_UP: gui_window_resize(w, 0, -11); break; case CTRL_DOWN: gui_window_resize(w, 0, 23); break; } } out_while: break; case 'e': case 'E': while(1){ key = gui_view_editing(view, 0); if(key == ESC) break; switch(key){ case UP: gui_view_move_up(view); break; case DOWN: gui_view_move_down(view); break; default: break; } } break; } } }
int main(int argc, char *argv[]) { Arg arglist[10]; Cardinal num_args; #ifdef USE_PRIVSEP struct passwd *pw; #endif XtSetLanguageProc(NULL,NULL,NULL); top = XtInitialize ("xconsole", "XConsole", options, XtNumber (options), &argc, argv); XtGetApplicationResources (top, (XtPointer)&app_resources, resources, XtNumber (resources), NULL, 0); #ifdef USE_PRIVSEP /* Revoke privileges if any */ if (getuid() == 0) { /* Running as root */ pw = getpwnam(XCONSOLE_USER); if (!pw) { fprintf(stderr, "%s user not found\n", XCONSOLE_USER); exit(2); } if (priv_init(pw->pw_uid, pw->pw_gid) < 0) { fprintf(stderr, "priv_init failed\n"); exit(2); } } else if (priv_init(-1, -1) < 0) { fprintf(stderr, "priv_init failed\n"); exit(2); } #endif if (app_resources.daemon) if (fork ()) exit (0); XtAddActions (actions, XtNumber (actions)); text = XtCreateManagedWidget ("text", asciiTextWidgetClass, top, NULL, 0); XtRealizeWidget (top); num_args = 0; XtSetArg(arglist[num_args], XtNiconic, &iconified); num_args++; XtGetValues(top, arglist, num_args); if (iconified) Iconified((Widget)NULL, (XEvent*)NULL, (String*)NULL, (Cardinal*)NULL); else Deiconified((Widget)NULL,(XEvent*)NULL,(String*)NULL,(Cardinal*)NULL); wm_delete_window = XInternAtom(XtDisplay(top), "WM_DELETE_WINDOW", False); (void) XSetWMProtocols (XtDisplay(top), XtWindow(top), &wm_delete_window, 1); XmuGetHostname (mit_console_name + MIT_CONSOLE_LEN, 255); mit_console = XInternAtom(XtDisplay(top), mit_console_name, False); if (XGetSelectionOwner (XtDisplay (top), mit_console)) { XtGetSelectionValue(top, mit_console, XA_STRING, InsertSelection, NULL, CurrentTime); } else { XtOwnSelection(top, mit_console, CurrentTime, ConvertSelection, LoseSelection, NULL); OpenConsole (); } #ifdef USE_OSM ioerror = XSetIOErrorHandler(IOError); #endif #ifdef USE_PRIVSEP if (pledge("stdio rpath sendfd recvfd", NULL) == -1) err(1, "pledge"); #endif XtMainLoop (); return 0; }
int main(int argc, const char ** argv) { struct IntuiMessage *winmsg; ULONG signals, conreadsig, windowsig; LONG lch; WORD InControl = 0; BOOL Done = FALSE; UBYTE ch, ibuf; UBYTE obuf[200]; BYTE error; FromWb = (argc==0L) ? TRUE : FALSE; if(!(IntuitionBase=OpenLibrary("intuition.library",0))) cleanexit("Can't open intuition\n",RETURN_FAIL); /* Create reply port and io block for writing to console */ if(!(writePort = CreatePort("RKM.console.write",0))) cleanexit("Can't create write port\n",RETURN_FAIL); if(!(writeReq = (struct IOStdReq *) CreateExtIO(writePort,(LONG)sizeof(struct IOStdReq)))) cleanexit("Can't create write request\n",RETURN_FAIL); /* Create reply port and io block for reading from console */ if(!(readPort = CreatePort("RKM.console.read",0))) cleanexit("Can't create read port\n",RETURN_FAIL); if(!(readReq = (struct IOStdReq *) CreateExtIO(readPort,(LONG)sizeof(struct IOStdReq)))) cleanexit("Can't create read request\n",RETURN_FAIL); /* Open a window */ if(!(win = OpenWindow(&nw))) cleanexit("Can't open window\n",RETURN_FAIL); /* Now, attach a console to the window */ if(error = OpenConsole(writeReq,readReq,win)) cleanexit("Can't open console.device\n",RETURN_FAIL); else OpenedConsole = TRUE; /* Demonstrate some console escape sequences */ ConPuts(writeReq,"Here's some normal text\n"); sprintf(obuf,"%s%sHere's text in color 3 & italics\n",COLOR03,ITALICS); ConPuts(writeReq,obuf); ConPuts(writeReq,NORMAL); Delay(50); /* Delay for dramatic demo effect */ ConPuts(writeReq,"We will now delete this asterisk =*="); Delay(50); ConPuts(writeReq,"\b\b"); /* backspace twice */ Delay(50); ConPuts(writeReq,DELCHAR); /* delete the character */ Delay(50); QueueRead(readReq,&ibuf); /* send the first console read request */ ConPuts(writeReq,"\n\nNow reading console\n"); ConPuts(writeReq,"Type some keys. Close window when done.\n\n"); conreadsig = 1 << readPort->mp_SigBit; windowsig = 1 << win->UserPort->mp_SigBit; while(!Done) { /* A character, or an IDCMP msg, or both could wake us up */ signals = Wait(conreadsig|windowsig); /* If a console signal was received, get the character */ if (signals & conreadsig) { if((lch = ConMayGetChar(readPort,&ibuf)) != -1) { ch = lch; /* Show hex and ascii (if printable) for char we got. * If you want to parse received control sequences, such as * function or Help keys,you would buffer control sequences * as you receive them, starting to buffer whenever you * receive 0x9B (or 0x1B[ for user-typed sequences) and * ending when you receive a valid terminating character * for the type of control sequence you are receiving. * For CSI sequences, valid terminating characters * are generally 0x40 through 0x7E. * In our example, InControl has the following values: * 0 = no, 1 = have 0x1B, 2 = have 0x9B OR 0x1B and [, * 3 = now inside control sequence, -1 = normal end esc, * -2 = non-CSI(no [) 0x1B end esc * NOTE - a more complex parser is required to recognize * other types of control sequences. */ /* 0x1B ESC not followed by '[', is not CSI seq */ if (InControl==1) { if(ch=='[') InControl = 2; else InControl = -2; } if ((ch==0x9B)||(ch==0x1B)) /* Control seq starting */ { InControl = (ch==0x1B) ? 1 : 2; ConPuts(writeReq,"=== Control Seq ===\n"); } /* We'll show value of this char we received */ if (((ch >= 0x1F)&&(ch <= 0x7E))||(ch >= 0xA0)) sprintf(obuf,"Received: hex %02x = %c\n",ch,ch); else sprintf(obuf,"Received: hex %02x\n",ch); ConPuts(writeReq,obuf); /* Valid ESC sequence terminator ends an ESC seq */ if ((InControl==3)&&((ch >= 0x40) && (ch <= 0x7E))) { InControl = -1; } if (InControl==2) InControl = 3; /* ESC sequence finished (-1 if OK, -2 if bogus) */ if (InControl < 0) { InControl = 0; ConPuts(writeReq,"=== End Control ===\n"); } } } /* If IDCMP messages received, handle them */ if (signals & windowsig) { /* We have to ReplyMsg these when done with them */ while (winmsg = (struct IntuiMessage *)GetMsg(win->UserPort)) { switch(winmsg->Class) { case IDCMP_CLOSEWINDOW: Done = TRUE; break; default: break; } ReplyMsg((struct Message *)winmsg); } } } /* We always have an outstanding queued read request * so we must abort it if it hasn't completed, * and we must remove it. */ if(!(CheckIO(readReq))) AbortIO(readReq); WaitIO(readReq); /* clear it from our replyport */ cleanup(); exit(RETURN_OK); }