process.c
来自「Wine-20031016」· C语言 代码 · 共 1,201 行 · 第 1/4 页
C
1,201 行
if (option && strcmp(option, "console") == 0) { CONSOLE_SCREEN_BUFFER_INFO sbi; HANDLE hConIn = GetStdHandle(STD_INPUT_HANDLE); HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE); DWORD modeIn, modeOut; childPrintf(hFile, "[Console]\n"); if (GetConsoleScreenBufferInfo(hConOut, &sbi)) { childPrintf(hFile, "SizeX=%d\nSizeY=%d\nCursorX=%d\nCursorY=%d\nAttributes=%d\n", sbi.dwSize.X, sbi.dwSize.Y, sbi.dwCursorPosition.X, sbi.dwCursorPosition.Y, sbi.wAttributes); childPrintf(hFile, "winLeft=%d\nwinTop=%d\nwinRight=%d\nwinBottom=%d\n", sbi.srWindow.Left, sbi.srWindow.Top, sbi.srWindow.Right, sbi.srWindow.Bottom); childPrintf(hFile, "maxWinWidth=%d\nmaxWinHeight=%d\n", sbi.dwMaximumWindowSize.X, sbi.dwMaximumWindowSize.Y); } childPrintf(hFile, "InputCP=%d\nOutputCP=%d\n", GetConsoleCP(), GetConsoleOutputCP()); if (GetConsoleMode(hConIn, &modeIn)) childPrintf(hFile, "InputMode=%ld\n", modeIn); if (GetConsoleMode(hConOut, &modeOut)) childPrintf(hFile, "OutputMode=%ld\n", modeOut); /* now that we have written all relevant information, let's change it */ ok(SetConsoleCP(1252), "Setting CP"); ok(SetConsoleOutputCP(1252), "Setting SB CP"); ok(SetConsoleMode(hConIn, modeIn ^ 1), "Setting mode (%ld)", GetLastError()); ok(SetConsoleMode(hConOut, modeOut ^ 1), "Setting mode (%ld)", GetLastError()); sbi.dwCursorPosition.X ^= 1; sbi.dwCursorPosition.Y ^= 1; ok(SetConsoleCursorPosition(hConOut, sbi.dwCursorPosition), "Setting cursor position (%ld)", GetLastError()); } if (option && strcmp(option, "stdhandle") == 0) { HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE); HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); if (hStdIn != INVALID_HANDLE_VALUE || hStdOut != INVALID_HANDLE_VALUE) { char buf[1024]; DWORD r, w; ok(ReadFile(hStdIn, buf, sizeof(buf), &r, NULL) && r > 0, "Reading message from input pipe"); childPrintf(hFile, "[StdHandle]\nmsg=%s\n\n", encodeA(buf)); ok(WriteFile(hStdOut, buf, r, &w, NULL) && w == r, "Writting message to output pipe"); } } if (option && strcmp(option, "exit_code") == 0) { childPrintf(hFile, "[ExitCode]\nvalue=%d\n\n", 123); CloseHandle(hFile); ExitProcess(123); } CloseHandle(hFile);}static char* getChildString(const char* sect, const char* key){ char buf[1024]; char* ret; GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), resfile); if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL; assert(!(strlen(buf) & 1)); ret = decodeA(buf); return ret;}/* FIXME: this may be moved to the wtmain.c file, because it may be needed by * others... (windows uses stricmp while Un*x uses strcasecmp...) */static int wtstrcasecmp(const char* p1, const char* p2){ char c1, c2; c1 = c2 = '@'; while (c1 == c2 && c1) { c1 = *p1++; c2 = *p2++; if (c1 != c2) { c1 = toupper(c1); c2 = toupper(c2); } } return c1 - c2;}static int strCmp(const char* s1, const char* s2, BOOL sensitive){ if (!s1 && !s2) return 0; if (!s2) return -1; if (!s1) return 1; return (sensitive) ? strcmp(s1, s2) : wtstrcasecmp(s1, s2);}#define okChildString(sect, key, expect) \ do { \ char* result = getChildString((sect), (key)); \ ok(strCmp(result, expect, 1) == 0, "%s:%s expected '%s', got '%s'", (sect), (key), (expect)?(expect):"(null)", result); \ } while (0)#define okChildIString(sect, key, expect) \ do { \ char* result = getChildString(sect, key); \ ok(strCmp(result, expect, 0) == 0, "%s:%s expected '%s', got '%s'", sect, key, expect, result); \ } while (0)/* using !expect insures that the test will fail if the sect/key isn't present * in result file */#define okChildInt(sect, key, expect) \ do { \ UINT result = GetPrivateProfileIntA((sect), (key), !(expect), resfile); \ ok(result == expect, "%s:%s expected %d, but got %d", (sect), (key), (int)(expect), result); \ } while (0)static void test_Startup(void){ char buffer[MAX_PATH]; PROCESS_INFORMATION info; STARTUPINFOA startup,si; /* let's start simplistic */ memset(&startup, 0, sizeof(startup)); startup.cb = sizeof(startup); startup.dwFlags = STARTF_USESHOWWINDOW; startup.wShowWindow = SW_SHOWNORMAL; get_file_name(resfile); sprintf(buffer, "%s tests/process.c %s", selfname, resfile); ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess"); /* wait for child to terminate */ ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination"); /* child process has changed result file, so let profile functions know about it */ WritePrivateProfileStringA(NULL, NULL, NULL, resfile); GetStartupInfoA(&si); okChildInt("StartupInfoA", "cb", startup.cb); okChildString("StartupInfoA", "lpDesktop", si.lpDesktop); okChildString("StartupInfoA", "lpTitle", si.lpTitle); okChildInt("StartupInfoA", "dwX", startup.dwX); okChildInt("StartupInfoA", "dwY", startup.dwY); okChildInt("StartupInfoA", "dwXSize", startup.dwXSize); okChildInt("StartupInfoA", "dwYSize", startup.dwYSize); okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars); okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars); okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute); okChildInt("StartupInfoA", "dwFlags", startup.dwFlags); okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow); release_memory(); assert(DeleteFileA(resfile) != 0); /* not so simplistic now */ memset(&startup, 0, sizeof(startup)); startup.cb = sizeof(startup); startup.dwFlags = STARTF_USESHOWWINDOW; startup.wShowWindow = SW_SHOWNORMAL; startup.lpTitle = "I'm the title string"; startup.lpDesktop = "I'm the desktop string"; startup.dwXCountChars = 0x12121212; startup.dwYCountChars = 0x23232323; startup.dwX = 0x34343434; startup.dwY = 0x45454545; startup.dwXSize = 0x56565656; startup.dwYSize = 0x67676767; startup.dwFillAttribute = 0xA55A; get_file_name(resfile); sprintf(buffer, "%s tests/process.c %s", selfname, resfile); ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess"); /* wait for child to terminate */ ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination"); /* child process has changed result file, so let profile functions know about it */ WritePrivateProfileStringA(NULL, NULL, NULL, resfile); okChildInt("StartupInfoA", "cb", startup.cb); okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop); okChildString("StartupInfoA", "lpTitle", startup.lpTitle); okChildInt("StartupInfoA", "dwX", startup.dwX); okChildInt("StartupInfoA", "dwY", startup.dwY); okChildInt("StartupInfoA", "dwXSize", startup.dwXSize); okChildInt("StartupInfoA", "dwYSize", startup.dwYSize); okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars); okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars); okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute); okChildInt("StartupInfoA", "dwFlags", startup.dwFlags); okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow); release_memory(); assert(DeleteFileA(resfile) != 0); /* not so simplistic now */ memset(&startup, 0, sizeof(startup)); startup.cb = sizeof(startup); startup.dwFlags = STARTF_USESHOWWINDOW; startup.wShowWindow = SW_SHOWNORMAL; startup.lpTitle = "I'm the title string"; startup.lpDesktop = NULL; startup.dwXCountChars = 0x12121212; startup.dwYCountChars = 0x23232323; startup.dwX = 0x34343434; startup.dwY = 0x45454545; startup.dwXSize = 0x56565656; startup.dwYSize = 0x67676767; startup.dwFillAttribute = 0xA55A; get_file_name(resfile); sprintf(buffer, "%s tests/process.c %s", selfname, resfile); ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess"); /* wait for child to terminate */ ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination"); /* child process has changed result file, so let profile functions know about it */ WritePrivateProfileStringA(NULL, NULL, NULL, resfile); okChildInt("StartupInfoA", "cb", startup.cb); okChildString("StartupInfoA", "lpDesktop", si.lpDesktop); okChildString("StartupInfoA", "lpTitle", startup.lpTitle); okChildInt("StartupInfoA", "dwX", startup.dwX); okChildInt("StartupInfoA", "dwY", startup.dwY); okChildInt("StartupInfoA", "dwXSize", startup.dwXSize); okChildInt("StartupInfoA", "dwYSize", startup.dwYSize); okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars); okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars); okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute); okChildInt("StartupInfoA", "dwFlags", startup.dwFlags); okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow); release_memory(); assert(DeleteFileA(resfile) != 0); /* not so simplistic now */ memset(&startup, 0, sizeof(startup)); startup.cb = sizeof(startup); startup.dwFlags = STARTF_USESHOWWINDOW; startup.wShowWindow = SW_SHOWNORMAL; startup.lpTitle = "I'm the title string"; startup.lpDesktop = ""; startup.dwXCountChars = 0x12121212; startup.dwYCountChars = 0x23232323; startup.dwX = 0x34343434; startup.dwY = 0x45454545; startup.dwXSize = 0x56565656; startup.dwYSize = 0x67676767; startup.dwFillAttribute = 0xA55A; get_file_name(resfile); sprintf(buffer, "%s tests/process.c %s", selfname, resfile); ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess"); /* wait for child to terminate */ ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination"); /* child process has changed result file, so let profile functions know about it */ WritePrivateProfileStringA(NULL, NULL, NULL, resfile); okChildInt("StartupInfoA", "cb", startup.cb); todo_wine okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop); okChildString("StartupInfoA", "lpTitle", startup.lpTitle); okChildInt("StartupInfoA", "dwX", startup.dwX); okChildInt("StartupInfoA", "dwY", startup.dwY); okChildInt("StartupInfoA", "dwXSize", startup.dwXSize); okChildInt("StartupInfoA", "dwYSize", startup.dwYSize); okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars); okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars); okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute); okChildInt("StartupInfoA", "dwFlags", startup.dwFlags); okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow); release_memory(); assert(DeleteFileA(resfile) != 0); /* not so simplistic now */ memset(&startup, 0, sizeof(startup)); startup.cb = sizeof(startup); startup.dwFlags = STARTF_USESHOWWINDOW; startup.wShowWindow = SW_SHOWNORMAL; startup.lpTitle = NULL; startup.lpDesktop = "I'm the desktop string"; startup.dwXCountChars = 0x12121212; startup.dwYCountChars = 0x23232323; startup.dwX = 0x34343434; startup.dwY = 0x45454545; startup.dwXSize = 0x56565656; startup.dwYSize = 0x67676767; startup.dwFillAttribute = 0xA55A; get_file_name(resfile); sprintf(buffer, "%s tests/process.c %s", selfname, resfile); ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess"); /* wait for child to terminate */ ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination"); /* child process has changed result file, so let profile functions know about it */ WritePrivateProfileStringA(NULL, NULL, NULL, resfile); okChildInt("StartupInfoA", "cb", startup.cb); okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop); okChildString("StartupInfoA", "lpTitle", si.lpTitle); okChildInt("StartupInfoA", "dwX", startup.dwX); okChildInt("StartupInfoA", "dwY", startup.dwY); okChildInt("StartupInfoA", "dwXSize", startup.dwXSize); okChildInt("StartupInfoA", "dwYSize", startup.dwYSize); okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?