int WINAPI WinMain (HINSTANCE hinstance, HINSTANCE hinstancePrev, LPSTR lpszCmdLine, int iCmdShow) { char *pch; HWND hwnd; OSVERSIONINFO osvi; // Obtain version number and determine if running Windows operating system // belongs to the Windows 95/98/ME family. Set the g_fOnWin95 flag to true // for Windows 95/98/ME family. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if (GetVersionEx (&osvi) || osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) g_fOnWin95 = TRUE; // If an exception occurs within the body of the following try statement, we // must handle that exception in the __except handler. That handler invokes // hogMachine() with a FALSE argument to re-enable the Alt+Tab, Windows, and // Ctrl+Alt+Delete keys. __try { // Save instance handle for later access in doConfig() and doSaver(). g_hinstance = hinstance; // Obtain the command line. pch = GetCommandLine (); // Process the command line. Example: "c:\bc45\projects\pscl\pscl.scr" /S // In some cases, there may not be double quotes. if (*pch == '\"') { // Skip open double quote. pch++; // Skip all characters until end of command line or close double // quote encountered. while (*pch != '\0' && *pch != '\"') pch++; } else { // Skip all characters until end of command line or space // encountered. while (*pch != '\0' && *pch != ' ') pch++; } // If *pch is not \0 (end of command line), it is either a double quote // or a space. Skip past this character. if (*pch != '\0') pch++; // Consume all intervening spaces. while (*pch == ' ') pch++; // If *pch is \0, no arguments were passed to the screensaver. Establish // smConfig as the screensaver mode, with the foreground window as the // parent window handle. if (*pch == '\0') { g_scrmode = smConfig; hwnd = GetForegroundWindow (); } else { // If we found an option, skip over option indicator. if (*pch == '-' || *pch == '/') pch++; // Detect valid option characters. if (*pch == 'a' || *pch == 'A') { // Establish smPassword as the screensaver mode. g_scrmode = smPassword; // Skip over option character. pch++; // Skip intervening spaces or colons. while (*pch == ' ' || *pch == ':') pch++; // Save handle argument as the parent window handle. hwnd = (HWND) atoi (pch); } else if (*pch == 'c' || *pch == 'C') { // Establish smConfig as the screensaver mode. g_scrmode = smConfig; // Skip over option character. pch++; // Skip intervening spaces or colons. while (*pch == ' ' || *pch ==':') pch++; // If nothing follows the option character (except for spaces and // colons), use the foreground window¡¯s handle as the parent // window handle. Otherwise, save the handle argument as the // parent window handle. if (*pch == '\0') hwnd = GetForegroundWindow (); else hwnd = (HWND) atoi (pch); } else if (*pch == 'p' || *pch == 'P' || *pch == 'l' || *pch == 'L') { // Establish smPreview as the screensaver mode. g_scrmode = smPreview; // Skip over option character. pch++; // Skip intervening spaces or colons. while (*pch == ' ' || *pch == ':') pch++; // Save handle argument as the parent window handle. hwnd = (HWND) atoi (pch); } else if (*pch == 's' || *pch == 'S') { // Establish smSaver as the screensaver mode. g_scrmode = smSaver; } } // Invoke appropriate screensaver entry point based on screensaver mode. if (g_scrmode == smConfig) doConfig (hwnd); else if (g_scrmode == smPassword) doChangePwd (hwnd); else if (g_scrmode == smPreview) doSaver (hwnd); else if (g_scrmode == smSaver) doSaver (NULL); } __except (EXCEPTION_EXECUTE_HANDLER) { hogMachine (FALSE); } return 0; }
int main() { int i; char* argv[8]; int argc; printf_register(serial_putchar); printf("waiting..."); // Wait a short while for(i = 0; i < 10000; ++i) asm volatile ("nop"); printf("configuring..."); i2c_init(); argv[0] = "1"; argc = 1; doConfig(argv, argc); printf("done.\n"); while (1) { printf("\n> "); argc = readcmd(argv, 8); printf("\r\n> "); if(argc > 0) { switch(argv[0][0]) { case 'S': doSet(argv, argc); break; case 'G': doGet(argv, argc); break; case 'R': doResult(argv, argc); break; case 'W': doWrite(argv, argc); break; case 'X': doRead(argv, argc); break; case 'Z': doStatus(argv, argc); break; case 'I': switch(argv[0][1]) { case 'I': i2c_init(); break; case 'W': doI2CWrite(argv, argc); break; case 'R': doI2CRead(argv, argc); break; case 'C': doConfig(argv, argc); break; } break; } } } }