void TestCompareF( void ) { char bufA[80] = "FoO baR gOoBeR bLaH"; char bufLower[80] = "foo bar goober blah"; char bufUpper[80] = "FOO BAR GOOBER BLAH"; int status; status = _fstrcmp( bufA, bufA ); /* ensure same */ VERIFY( status == 0 ); status = _fstrcmp( bufA, bufLower ); /* ensure not same */ VERIFY( status != 0 ); status = _fstricmp( bufA, bufUpper ); /* ensure same */ VERIFY( status == 0 ); status = _fstricmp( bufA, "foo" ); /* ensure not same */ VERIFY( status != 0 ); status = _fstrncmp( bufA, bufA, 100 ); /* ensure same */ VERIFY( status == 0 ); status = _fstrncmp( bufA, bufLower, 1 ); /* ensure not same */ VERIFY( status != 0 ); status = _fstrnicmp( bufA, bufUpper, 100 ); /* ensure same */ VERIFY( status == 0 ); status = _fstrnicmp( bufA, "fOo B!!!", 5 ); /* ensure same */ VERIFY( status == 0 ); status = _fstrnicmp( bufA, "fOo B!!!", 6 ); /* ensure not same */ VERIFY( status != 0 ); }
//*********************************************************************** int CParser::GetNextToken() // return next token in the script //*********************************************************************** { if (!m_lpScript) return I_EOF; int i; int wWordLen, wLen; pCParseToken pToken; LPSTR pWord; if (wWordLen = GetNextWord()) { pWord = m_lpScript; // the word it just located m_lpScript += wWordLen; // just after this word for (i=0; (pToken = &TokenList[i]) && pToken->GetID(); i++) { LPSTR lpToken = pToken->GetToken(); wLen = pToken->GetTokenLen(); if ((wWordLen == wLen) && (_fstrnicmp(lpToken, pWord, wLen) == 0)) { BOOL bResult = TRUE; for (int q=0; bResult && q<pToken->GetParams(); q++) bResult = GetNextNum(&m_Params[q]); if (!bResult) RecordError(pToken, ERR_INSUF); return bResult ? pToken->GetID() : NULL; // found one. } } // cannot find that command char command[100]; command[0] = 0; lstrcpyn(command, pWord, wWordLen+1); CParseToken Dummy((LPSTR)command, 0, 0); RecordError(&Dummy, ERR_UNKNOWN); return NULL; } // no more words in the script return I_EOF; }
/****************************************************************************** * int WinMain( * HINSTANCE hinstCurrent, * HINSTANCE hinstPrevious, * LPSTR lpszCmdLine, * int nCmdShow); * * windows initialization and exit * * parameters: * hinstCurrent - handle to this instance of minerva * hinstPrevious - handle to previous instance of minerva. If hinstPrevious is * NULL, no other instance is active (this is the first and only instance). * lpszCmdLine - command line parameters to this instance * nCmdShow - see ShowWindow() documentation * * returns: * value to be set as exit code for application * * notes: * WinMain is called as the application is starting up. When WinMain returns, * the application is terminated. ******************************************************************************/ int PASCAL WinMain( HINSTANCE hinstCurrent, /* handle to this instance */ HINSTANCE hinstPrevious, /* handle to previous instance or NULL */ LPSTR lpszCmdLine, /* command line */ int nCmdShow) /* see ShowWindow() documentation */ { MSG msg; LPCSTR psz; NOREFERENCE(lpszCmdLine); /* make SURE that (LPBITMAPINFO)&PIC_PARM.Head is valid */ assert(offsetof(PIC_PARM, ColorTable) - offsetof(PIC_PARM, Head) == offsetof(BITMAPINFO, bmiColors) - offsetof(BITMAPINFO, bmiHeader)); hinstThis = hinstCurrent; /* instance handle is globally accessible */ /* allow ctl3d to hook us */ Ctl3dRegister(hinstThis); /* dialogs and controls are automatically 3d */ Ctl3dAutoSubclass(hinstThis); if ( hinstPrevious == NULL ) { /* register window classes for first instance only hinstPrevious == NULL if and only if this is the only active instance of minerva */ if ( !RegisterWindowClasses() ) { Ctl3dUnregister(hinstCurrent); return ( 0 ); } } /* keyboard accelerators for menu commands */ hAcceleratorTable = LoadAccelerators(hinstThis, "MinervaAccelerators"); if ( hAcceleratorTable == NULL ) { ErrorMessage(STYLE_FATAL, IDS_LOADACCELERATORS); /* "An unexpected LoadAccelerators error occurred. Minerva cannot continue." */ Ctl3dUnregister(hinstCurrent); return ( 0 ); } if ( !CreateFrameWindow(nCmdShow) ) { Ctl3dUnregister(hinstCurrent); return ( 0 ); } /* load MRU file list from minerva.ini and update File menu */ if ( !MruLoadList(hwndFrame, APPLICATION_INIFILENAME) ) { DestroyWindow(hwndFrame); Ctl3dUnregister(hinstCurrent); return ( 0 ); } hWaitCursor = LoadCursor(NULL, IDC_WAIT); hArrowCursor = LoadCursor(NULL, IDC_ARROW); hHandCursor = LoadCursor(hinstThis, MAKEINTRESOURCE(IDC_HAND)); assert(hWaitCursor != NULL && hArrowCursor != NULL && hHandCursor != NULL); /* load PIC opcode DLL's */ InitOpList(); bDisableRDTSC = GetPrivateProfileInt("Settings", "DisableRDTSC", 0, APPLICATION_INIFILENAME); psz = lpszCmdLine + _fstrspn(lpszCmdLine, " "); while ( psz != 0 && ( *psz == '-' || *psz == '/' || *psz == '+' ) ) { if ( _fstrnicmp(psz + 1, "RDTSC", sizeof("RDTSC") - 1) == 0 && psz[sizeof("RDTSC")] <= ' ' ) bDisableRDTSC = *psz != '+'; psz = _fstrpbrk(psz, " "); if ( psz != 0 ) psz += _fstrspn(psz, " "); } if ( !bDisableRDTSC ) MiscTickCount(); // calibrate the RDTSC ticks while ( GetMessage(&msg, NULL, 0, 0) ) { if ( !TranslateMDISysAccel(hwndMDIClient, &msg) && !TranslateAccelerator(hwndFrame, hAcceleratorTable, &msg) ) { TranslateMessage(&msg); DispatchMessage(&msg); } } DestroyCursor(hHandCursor); /* unload PIC opcode DLL's */ CleanupOpList(); /* save MRU file list to minerva.ini */ MruSaveList(APPLICATION_INIFILENAME); Ctl3dUnregister(hinstCurrent); return ( msg.wParam ); }
int main(int argc, char **argv) #endif { LPSTR tail; int i; #ifdef WGP_CONSOLE HINSTANCE hInstance = GetModuleHandle(NULL), hPrevInstance = NULL; #endif #ifndef WGP_CONSOLE # if defined( __MINGW32__) && !defined(_W64) # define argc _argc # define argv _argv # else /* MSVC, WATCOM, MINGW-W64 */ # define argc __argc # define argv __argv # endif #endif /* WGP_CONSOLE */ szModuleName = (LPSTR)malloc(MAXSTR+1); CheckMemory(szModuleName); /* get path to EXE */ GetModuleFileName(hInstance, (LPSTR) szModuleName, MAXSTR); if ((tail = (LPSTR)_fstrrchr(szModuleName,'\\')) != (LPSTR)NULL) { tail++; *tail = 0; } szModuleName = (LPSTR)realloc(szModuleName, _fstrlen(szModuleName)+1); CheckMemory(szModuleName); if (_fstrlen(szModuleName) >= 5 && _fstrnicmp(&szModuleName[_fstrlen(szModuleName)-5], "\\bin\\", 5) == 0) { int len = _fstrlen(szModuleName)-4; szPackageDir = (LPSTR)malloc(len+1); CheckMemory(szPackageDir); _fstrncpy(szPackageDir, szModuleName, len); szPackageDir[len] = '\0'; } else szPackageDir = szModuleName; #ifndef WGP_CONSOLE textwin.hInstance = hInstance; textwin.hPrevInstance = hPrevInstance; textwin.nCmdShow = nCmdShow; textwin.Title = "gnuplot"; #endif /* create structure of first graph window */ graphwin = (LPGW) calloc(1, sizeof(GW)); listgraphs = graphwin; /* locate ini file */ { char * inifile; get_user_env(); /* this hasn't been called yet */ inifile = gp_strdup("~\\wgnuplot.ini"); gp_expand_tilde(&inifile); /* if tilde expansion fails use current directory as default - that was the previous default behaviour */ if (inifile[0] == '~') { free(inifile); inifile = "wgnuplot.ini"; } #ifndef WGP_CONSOLE textwin.IniFile = inifile; #endif graphwin->IniFile = inifile; ReadMainIni(inifile, "WGNUPLOT"); } #ifndef WGP_CONSOLE textwin.IniSection = "WGNUPLOT"; textwin.DragPre = "load '"; textwin.DragPost = "'\n"; textwin.lpmw = &menuwin; textwin.ScreenSize.x = 80; textwin.ScreenSize.y = 80; textwin.KeyBufSize = 2048; textwin.CursorFlag = 1; /* scroll to cursor after \n & \r */ textwin.shutdown = MakeProcInstance((FARPROC)ShutDown, hInstance); textwin.AboutText = (LPSTR)malloc(1024); CheckMemory(textwin.AboutText); sprintf(textwin.AboutText, "Version %s patchlevel %s\n" \ "last modified %s\n" \ "%s\n%s, %s and many others\n" \ "gnuplot home: http://www.gnuplot.info\n", gnuplot_version, gnuplot_patchlevel, gnuplot_date, gnuplot_copyright, authors[1], authors[0]); textwin.AboutText = (LPSTR)realloc(textwin.AboutText, _fstrlen(textwin.AboutText)+1); CheckMemory(textwin.AboutText); menuwin.szMenuName = szMenuName; #endif pausewin.hInstance = hInstance; pausewin.hPrevInstance = hPrevInstance; pausewin.Title = "gnuplot pause"; graphwin->hInstance = hInstance; graphwin->hPrevInstance = hPrevInstance; #ifdef WGP_CONSOLE graphwin->lptw = NULL; #else graphwin->lptw = &textwin; #endif /* init common controls */ { INITCOMMONCONTROLSEX initCtrls; initCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX); initCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&initCtrls); } #ifndef WGP_CONSOLE if (TextInit(&textwin)) gp_exit(EXIT_FAILURE); textwin.hIcon = LoadIcon(hInstance, "TEXTICON"); SetClassLongPtr(textwin.hWndParent, GCLP_HICON, (LONG_PTR)textwin.hIcon); /* Note: we want to know whether this is an interactive session so that we can * decide whether or not to write status information to stderr. The old test * for this was to see if (argc > 1) but the addition of optional command line * switches broke this. What we really wanted to know was whether any of the * command line arguments are file names or an explicit in-line "-e command". * (This is a copy of a code snippet from plot.c) */ for (i = 1; i < argc; i++) { if (!stricmp(argv[i], "/noend")) continue; if ((argv[i][0] != '-') || (argv[i][1] == 'e')) { interactive = FALSE; break; } } if (interactive) ShowWindow(textwin.hWndParent, textwin.nCmdShow); if (IsIconic(textwin.hWndParent)) { /* update icon */ RECT rect; GetClientRect(textwin.hWndParent, (LPRECT) &rect); InvalidateRect(textwin.hWndParent, (LPRECT) &rect, 1); UpdateWindow(textwin.hWndParent); } # ifndef __WATCOMC__ /* Finally, also redirect C++ standard output streams. */ RedirectOutputStreams(TRUE); # endif #else /* WGP_CONSOLE */ #ifdef CONSOLE_SWITCH_CP /* Change codepage of console to match that of the graph window. WinExit() will revert this. Attention: display of characters does not work correctly with "Terminal" font! Users will have to use "Lucida Console" or similar. */ cp_input = GetConsoleCP(); cp_output = GetConsoleOutputCP(); if (cp_input != GetACP()) { cp_changed = TRUE; SetConsoleCP(GetACP()); /* keyboard input */ SetConsoleOutputCP(GetACP()); /* screen output */ SetFileApisToANSI(); /* file names etc. */ } #endif #endif gp_atexit(WinExit); if (!isatty(fileno(stdin))) setmode(fileno(stdin), O_BINARY); gnu_main(argc, argv); /* First chance to close help system for console gnuplot, second for wgnuplot */ WinCloseHelp(); gp_exit_cleanup(); return 0; }
int main(int argc, char **argv) #endif { /*WNDCLASS wndclass;*/ LPSTR tail; #ifdef WGP_CONSOLE # define _argv argv # define _argc argc HINSTANCE hInstance = GetModuleHandle(NULL), hPrevInstance = NULL; #else #if defined(__MSC__) || defined(__WATCOMC__) # define _argv __argv # define _argc __argc #endif #endif /* WGP_CONSOLE */ szModuleName = (LPSTR)malloc(MAXSTR+1); CheckMemory(szModuleName); /* get path to EXE */ GetModuleFileName(hInstance, (LPSTR) szModuleName, MAXSTR); if ((tail = (LPSTR)_fstrrchr(szModuleName,'\\')) != (LPSTR)NULL) { tail++; *tail = 0; } szModuleName = (LPSTR)realloc(szModuleName, _fstrlen(szModuleName)+1); CheckMemory(szModuleName); if (_fstrlen(szModuleName) >= 5 && _fstrnicmp(&szModuleName[_fstrlen(szModuleName)-5], "\\bin\\", 5) == 0) { int len = _fstrlen(szModuleName)-4; szPackageDir = (LPSTR)malloc(len+1); CheckMemory(szPackageDir); _fstrncpy(szPackageDir, szModuleName, len); szPackageDir[len] = '\0'; } else szPackageDir = szModuleName; #ifndef WGP_CONSOLE textwin.hInstance = hInstance; textwin.hPrevInstance = hPrevInstance; textwin.nCmdShow = nCmdShow; textwin.Title = "gnuplot"; #endif /* create structure of first graph window */ graphwin = calloc(1, sizeof(GW)); listgraphs = graphwin; /* locate ini file */ { char * inifile; get_user_env(); /* this hasn't been called yet */ inifile = gp_strdup("~\\wgnuplot.ini"); gp_expand_tilde(&inifile); /* if tilde expansion fails use current directory as default - that was the previous default behaviour */ if (inifile[0] == '~') { free(inifile); inifile = "wgnuplot.ini"; } #ifndef WGP_CONSOLE textwin.IniFile = inifile; #endif graphwin->IniFile = inifile; ReadMainIni(inifile, "WGNUPLOT"); } #ifndef WGP_CONSOLE textwin.IniSection = "WGNUPLOT"; textwin.DragPre = "load '"; textwin.DragPost = "'\n"; textwin.lpmw = &menuwin; textwin.ScreenSize.x = 80; textwin.ScreenSize.y = 80; textwin.KeyBufSize = 2048; textwin.CursorFlag = 1; /* scroll to cursor after \n & \r */ textwin.shutdown = MakeProcInstance((FARPROC)ShutDown, hInstance); textwin.AboutText = (LPSTR)malloc(1024); CheckMemory(textwin.AboutText); sprintf(textwin.AboutText, "Version %s patchlevel %s\n" \ "last modified %s\n" \ "%s\n%s, %s and many others\n" \ "gnuplot home: http://www.gnuplot.info\n", gnuplot_version, gnuplot_patchlevel, gnuplot_date, gnuplot_copyright, authors[1], authors[0]); textwin.AboutText = (LPSTR)realloc(textwin.AboutText, _fstrlen(textwin.AboutText)+1); CheckMemory(textwin.AboutText); menuwin.szMenuName = szMenuName; #endif pausewin.hInstance = hInstance; pausewin.hPrevInstance = hPrevInstance; pausewin.Title = "gnuplot pause"; graphwin->hInstance = hInstance; graphwin->hPrevInstance = hPrevInstance; #ifdef WGP_CONSOLE graphwin->lptw = NULL; #else graphwin->lptw = &textwin; #endif /* init common controls */ { INITCOMMONCONTROLSEX initCtrls; initCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX); initCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&initCtrls); } #ifndef WGP_CONSOLE if (TextInit(&textwin)) exit(1); textwin.hIcon = LoadIcon(hInstance, "TEXTICON"); SetClassLong(textwin.hWndParent, GCL_HICON, (DWORD)textwin.hIcon); if (_argc>1) { int i,noend=FALSE; for (i=0; i<_argc; ++i) if (!stricmp(_argv[i],"-noend") || !stricmp(_argv[i],"/noend") || !stricmp(_argv[i],"-persist")) noend = TRUE; if (noend) ShowWindow(textwin.hWndParent, textwin.nCmdShow); } else ShowWindow(textwin.hWndParent, textwin.nCmdShow); if (IsIconic(textwin.hWndParent)) { /* update icon */ RECT rect; GetClientRect(textwin.hWndParent, (LPRECT) &rect); InvalidateRect(textwin.hWndParent, (LPRECT) &rect, 1); UpdateWindow(textwin.hWndParent); } #else /* WGP_CONSOLE */ #ifdef CONSOLE_SWITCH_CP /* Change codepage of console to match that of the graph window. WinExit() will revert this. Attention: display of characters does not work correctly with "Terminal" font! Users will have to use "Lucida Console" or similar. */ cp_input = GetConsoleCP(); cp_output = GetConsoleOutputCP(); if (cp_input != GetACP()) { cp_changed = TRUE; SetConsoleCP(GetACP()); /* keyboard input */ SetConsoleOutputCP(GetACP()); /* screen output */ SetFileApisToANSI(); /* file names etc. */ } #endif #endif atexit(WinExit); if (!isatty(fileno(stdin))) setmode(fileno(stdin), O_BINARY); gnu_main(_argc, _argv, environ); /* First chance to close help system for console gnuplot, second for wgnuplot */ WinCloseHelp(); return 0; }
BOOL LoadSoundData( HWND hwndParent, SOUND_DATA *psd, LPSTR szFile ) { int i, n, f_tag, f_channels, f_bits_per_sample; long f_len, f_sample_rate, data_offset, data_size; HFILE fh; BYTE huge *pData; CHAR szBuf[256]; fh = _lopen( szFile, READ ); if ( fh == HFILE_ERROR ) { MsgBox( hwndParent, MB_ICONEXCLAMATION, "Unable to open %s", (LPSTR)szFile ); return FALSE; } _fmemset( szBuf, 0, sizeof(szBuf) ); if ( _lread( fh, szBuf, sizeof(szBuf) ) < 4 ) { _lclose(fh); MsgBox( hwndParent, MB_ICONEXCLAMATION, "Error reading sound file header for %s", (LPSTR)szFile ); return FALSE; } i = 0; n = 0; while( i < sizeof(szBuf) - 4 ) { if ( _fstrnicmp( &szBuf[i], "RIFF", 4 ) == 0 ) { n = 1; i += 8; } else if ( _fstrnicmp( &szBuf[i], "WAVE", 4 ) == 0 ) { if ( n < 1 ) { break; } n = 2; i += 4; } else if ( _fstrnicmp( &szBuf[i], "fmt", 3 ) == 0 ) { if ( n < 2 ) { break; } f_len = *((long *)(&szBuf[i+4])); f_tag = *((int *)(&szBuf[i+8])); f_channels = *((int *)(&szBuf[i+10])); f_sample_rate = *((long *)(&szBuf[i+12])); f_bits_per_sample = *((int *)(&szBuf[i+22])); n = 3; i += (int)f_len + 8; } else if ( _fstrnicmp( &szBuf[i], "data", 4 ) == 0 ) { data_offset = (long)(i + 8); data_size = *((long *)(&szBuf[i+4])); n = 4; break; } else { ++i; } } if ( n != 4 ) { _lclose(fh); MsgBox( hwndParent, MB_ICONEXCLAMATION, "Unable to find sound data in %s", (LPSTR)szFile ); return FALSE; } if ( f_tag != 1 ) { _lclose(fh); MsgBox( hwndParent, MB_ICONEXCLAMATION, "Data in %s is not in PCM format.", (LPSTR)szFile ); return FALSE; } if ( f_channels != 1 ) { _lclose(fh); MsgBox( hwndParent, MB_ICONEXCLAMATION, "Data in %s is not single channel (mono).", (LPSTR)szFile ); return FALSE; } if ( f_sample_rate < 22000 || f_sample_rate > 22100 ) { _lclose(fh); MsgBox( hwndParent, MB_ICONEXCLAMATION, "Data in %s was recorded at %ldHz (22050Hz required).", (LPSTR)szFile, f_sample_rate ); return FALSE; } if ( f_bits_per_sample != 8 ) { _lclose(fh); MsgBox( hwndParent, MB_ICONEXCLAMATION, "Data in %s is not 8 bit data.", (LPSTR)szFile ); return FALSE; } if ( data_size == 0L ) { _lclose(fh); MsgBox( hwndParent, MB_ICONEXCLAMATION, "Data in %s has zero length.", (LPSTR)szFile ); return FALSE; } pData = (BYTE huge *)GlobalAllocPtr( GPTR, (DWORD)data_size ); if ( pData == NULL ) { _lclose(fh); MsgBox( hwndParent, MB_ICONEXCLAMATION, "Out of memory reading sound file %s", (LPSTR)szFile ); return FALSE; } _llseek( fh, data_offset, SEEK_SET ); if ( _hread( fh, pData, data_size ) != data_size ) { GlobalFreePtr( pData ); _lclose(fh); MsgBox( hwndParent, MB_ICONEXCLAMATION, "Error reading sound file for %s", (LPSTR)szFile ); return FALSE; } _lclose(fh); psd->length = data_size; psd->data = pData; #if 0 // // Convert from unsigned 8 bit data to signed 8 bit data. // while( data_size > 0L ) { *pData++ -= 128; --data_size; } #endif return TRUE; } // LoadSoundData