void WriteDiagFile( LPTSTR lpd ) { int i = strlen(lpd); if( i && ( hDbgFile == 0 ) ) { LPTSTR pfn = szDbgFile; GetModulePath(pfn); strcat(pfn, szDefDbg); OpenDiagFile( pfn, &hDbgFile, FALSE ); // TRUE ); } if( i && VFH(hDbgFile) ) { if( !outstg( hDbgFile, lpd, i ) ) { CloseHandle( hDbgFile ); hDbgFile = INVALID_HANDLE_VALUE; } } }
//--------------------------------------------------------------------------- // ParseCommandLine // // This routine parses the command line given. If the command line is valid, // then it is assumed that the user's intention is to execute the test given // and then exit -- without using the UI for anything. Else, we display the // usage message box (if the cmdline wasn't valid), and return. // // RETURNS: NULL if cmdline was valid (script run made, or attempted), // or if command line was invalid and usage was given, // OR pointer to script to load if /RUN not present given. // // NOTE: If no script was given, this function returns a ptr // to a null string. //--------------------------------------------------------------------------- HANDLE *ParseCommandLine (LPSTR cmdline) { CHAR *tok, *scr; INT doit = 0, scriptfound = 0; static HANDLE hScr[9] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; #ifdef DEBUG fDiags = 0; #endif // We always return at least one file name, so allocate it now //----------------------------------------------------------------------- listflag = 0; if (!(hScr[0] = LocalAlloc (LHND, 128))) { MPError (NULL, MB_OK | MB_ICONEXCLAMATION, IDS_OUTOFMEM); return (NULL); } scr = LocalLock (hScr[0]); // Return now if no cmdline args given //----------------------------------------------------------------------- scr[0] = 0; tok = GetCmdToken(cmdline); if (!tok) return (hScr); do { // Check here for the /T (testmode) switch and get its parameter //------------------------------------------------------------------- if (!_stricmp (tok, "/T") || !_stricmp (tok, "-T")) { tok = GetCmdToken(cmdline); if (!tok) { Usage(); return (NULL); } lstrcpy (tmbuf, tok); } // Here we check for /C (command) switch //------------------------------------------------------------------- else if (!_stricmp (tok, "/C") || !_stricmp (tok, "-C")) { tok = GetCmdToken(cmdline); if (!tok) { Usage(); return (NULL); } lstrcpy (cmdbuf, tok); } // /NOE (no error dialog) //------------------------------------------------------------------- else if (!_stricmp (tok, "/NOE") || !_stricmp (tok, "-NOE")) { NOERRDLG = 1; } // /A (filename) switch (produce assembly listing/diagnostics) //------------------------------------------------------------------- else if (!_stricmp (tok, "/A") || !_stricmp (tok, "-A")) { tok = GetCmdToken (cmdline); if (!tok) { Usage(); return (NULL); } SetAssemblyListFile (tok); } // /RUN switch //------------------------------------------------------------------- else if (!_stricmp (tok, "/RUN") || !_stricmp (tok, "-RUN")) { doit = 1; } #ifdef DEBUG else if (!_stricmp (tok, "/DIAG") || !_stricmp (tok, "-DIAG")) { fDiags = 1; } #endif // /D (define) switch //------------------------------------------------------------------- else if (!_stricmp (tok, "/D") || !_stricmp (tok, "-D")) { tok = GetCmdToken(cmdline); if (!tok) { Usage(); return (NULL); } if (SymCount == 16) { MPError (NULL, MB_OK | MB_ICONSTOP, IDS_MANYSYMBOLS); return (NULL); } _fstrncpy (DefSym[SymCount], tok, MAXSYMLEN); DefSym[SymCount++][MAXSYMLEN] = 0; } // If this was nothing above, we assume it's a script name //------------------------------------------------------------------- else if (scriptfound < 8) { if (!hScr[scriptfound]) { if (!(hScr[scriptfound] = LocalAlloc (LHND, 128))) { MPError (NULL, MB_OK | MB_ICONEXCLAMATION, IDS_OUTOFMEM); return (NULL); } scr = LocalLock (hScr[scriptfound]); } lstrcpy (scr, tok); LocalUnlock (hScr[scriptfound]); scriptfound += 1; } // Must have given too many script names //------------------------------------------------------------------- else { Usage (); return (NULL); } } while (tok = GetCmdToken(cmdline)); // No error dialog gets nullified if we're running the environment //----------------------------------------------------------------------- if (NOERRDLG && (!doit)) NOERRDLG = 0; // Return a pointer to the scripts given if no /RUN switch given //----------------------------------------------------------------------- if (!doit) return (hScr); // Give an error if no script name found, or more than one //----------------------------------------------------------------------- if (scriptfound != 1) { Usage (); return (NULL); } // Okay, we got a valid cmdline and we need to run. Send the script to // the parsing engine. // // NEW: Create a simple window which stays minimized and behind every // NEW: other window. The window text for this will contain the name // NEW: of the script running. //----------------------------------------------------------------------- EnsureExt (scr, 80); AnsiUpper (scr); Command = cmdbuf; TestMode = tmbuf; // KLUDGE: Call peekmessage to yield once... { MSG msg; CHAR buf[256], fmt[40]; PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE); // Change the window text of the viewport for this guy... //----------------------------------------------------------------------- if (LoadString (hInst, IDS_VPRUNTITLE, fmt, sizeof(fmt))) { wsprintf (buf, fmt, (LPSTR)scr); SetWindowText (hwndViewPort, buf); } } // Here's where we create the dummy window //----------------------------------------------------------------------- hwndDummy = CreateWindow (szRBRun, (LPSTR)scr, WS_OVERLAPPED|WS_SYSMENU, 0, 0, 0, 0, NULL, NULL, hInst, NULL); SetWindowPos (hwndDummy, (HWND)1, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); ShowWindow (hwndDummy, SW_SHOWMINNOACTIVE); // Okay, here we go. //----------------------------------------------------------------------- if (InitParser ()) { // HACKHACK: ntbldrus (kenhia) - on x86, complains about uninit var // 41 lines below (in final else WITHIN this if block) HCURSOR hOld = 0; // Initialize the scanner //------------------------------------------------------------------- if (BeginScan (scr, CBLoaderImmediate, SymCount, DefPtrs)) { #ifdef DEBUG if (fDiags) OpenDiagFile (scr); #endif hOld = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (!PcodeCompile()) { if (PcodeFixup(0)) { SetCursor (hOld); PcodeExecute(PE_RUN, NULL); DestroyWindow (hwndDummy); DestroyWindow (hwndViewPort); exit (ExitVal); } else { SetCursor (hOld); DestroyWindow (hwndDummy); DestroyWindow (hwndViewPort); exit (1); } } else { SetCursor (hOld); DestroyWindow (hwndDummy); DestroyWindow (hwndViewPort); exit (1); } EndScan (); } else { SetCursor (hOld); AbortParser(); MPError (NULL, MB_OK | MB_ICONSTOP, IDS_CANTREAD, (LPSTR)scr); DestroyWindow (hwndDummy); DestroyWindow (hwndViewPort); exit (1); } } else MPError (NULL, MB_OK | MB_ICONSTOP, IDS_CANTINIT); DestroyWindow (hwndViewPort); DestroyWindow (hwndDummy); exit (1); }
void WriteDiagFile_OK_but_why( LPTSTR lpd ) { int i, j, k; char buf[260]; char c, d; LPTSTR lpb; i = 0; if( lpd ) i = lstrlen( lpd ); if(i) { if( hDbgFile == 0 ) { GetModuleFileName(NULL, szDbgFile, 256); lpb = strrchr( szDbgFile, '\\' ); if(lpb) lpb++; else lpb = szDbgFile; strcpy(lpb, szDefDbg); OpenDiagFile( &szDbgFile[0], &hDbgFile, FALSE ); // TRUE ); } if( VFH(hDbgFile) ) { lpb = &buf[0]; k = 0; d = c = 0; for( j = 0; j < i; j++ ) { c = lpd[j]; if( c == 0x0a ) // A LF { if( d != 0x0d ) { lpb[k++] = 0x0d; } } else if( c == 0x0d ) // A CR { if( (j+1) < i ) // If more { if( lpd[j+1] != 0x0a ) { lpb[k++] = c; c = 0x0a; } } else { lpb[k++] = c; c = 0x0a; } } lpb[k++] = c; d = c; // Keep previous put } if( k ) { if( c != 0x0a ) { lpb[k++] = 0x0d; lpb[k++] = 0x0a; } if( !outstg( hDbgFile, lpb, k ) ) { CloseHandle( hDbgFile ); hDbgFile = INVALID_HANDLE_VALUE; } } } } }