home *** CD-ROM | disk | FTP | other *** search
- // GptUtil.cpp - utility c routines
- // copyright 1992 Pittsburgh Supercomputing Center
- #include "gpt.h"
- #include <stdio.h>
- // ****** SeparateFile
- // separate srcFileName into a DestFilePath and DestFileName
- #if (sizeof( int) <= 16)
- #endif
-
- void SeparateFile(LPSTR lpDestPath, LPSTR lpDestFileName, LPSTR lpDestExt,
- LPSTR lpSrcFileName)
- {
- LPSTR lpTmp;
- BYTE cTmp;
-
- lpTmp = lpSrcFileName + (long)lstrlen(lpSrcFileName);
- while (*lpTmp != ':' && *lpTmp !='\\' && lpTmp >lpSrcFileName)
- lpTmp = AnsiPrev(lpSrcFileName,lpTmp);
- if (*lpTmp != ':' && *lpTmp != '\\') //lpSrcFileName has no path part
- {
- lstrcpy( lpDestFileName, lpSrcFileName);
- lpDestPath[0] = 0;
- }
- else
- {
- lstrcpy(lpDestFileName, lpTmp + 1); // filename without path
- cTmp = *(lpTmp + 1);
- lstrcpy(lpDestPath,lpSrcFileName);
- *(lpTmp+1) = cTmp;
- lpDestPath[(lpTmp -lpSrcFileName) +1] = 0;
- }
- lpTmp = lpDestFileName + (long)lstrlen(lpDestFileName);
- while (*lpTmp != '.' && lpTmp >lpDestFileName)
- lpTmp = AnsiPrev(lpDestFileName,lpTmp);
- if (*lpTmp == '.' ) //lpDestFileName has ext part
- lstrcpy( lpDestExt, lpTmp);
-
- }
-
-
- // ***** ChangeDefExt
- // Change Default Extension to non-wildcard extension in Name
- void ChangeDefExt(LPSTR Ext, LPSTR Name)
- {
- LPSTR pTptr;
- pTptr = Name;
- while (*pTptr && *pTptr != '.') pTptr ++;
- if (*pTptr) // if really an extenstion
- if (!_fstrchr(pTptr, '*') && !_fstrchr(pTptr,'?') ) _fstrcpy(Ext, pTptr);
- }
- // ******* AddExt(Name, Ext)
- // Add Ext to Name if none exists
- void AddExt(PSTR Name, PSTR Ext)
- {
- PSTR pTptr;
- pTptr = Name;
- while (*pTptr && *pTptr != '.') pTptr++;
- if ( *pTptr !='.') strcat(Name, Ext);
- }
-
-
- // ******* ChangeExt(Name, Ext)
- // Change Ext to Name
- void ChangeExt(LPSTR Name, LPSTR Ext)
- {
- LPSTR pTptr;
- pTptr = Name;
- while (*pTptr && *pTptr != '.') pTptr++;
- if ( *pTptr =='.') _fstrcpy(pTptr, Ext);
- }
-
-
-
- LPSTR lstrchr (LPSTR str, char ch)
- {
- while (*str)
- {
- if (ch == *str)
- return str ;
-
- str = AnsiNext (str) ;
- }
- return NULL ;
- }
-
- // ********* lstrrchr
- // return LPSTR of last occurence of ch in str or NULL if not found
- LPSTR lstrrchr (LPSTR str, char ch)
- {
- LPSTR strl = str + lstrlen (str) ;
-
- do
- {
- if (ch == *strl)
- return strl ;
-
- strl = AnsiPrev (str, strl) ;
- }
- while (strl > str) ;
-
- return NULL ;
- }
-
-
- // *** OKMsgBox
- void OKMsgBox( char *szCaption, char *szFormat, ...)
- {
- char szBuffer[256];
- char *pArguments;
- pArguments = (char *)&szFormat + sizeof szFormat;
- vsprintf(szBuffer, szFormat, pArguments);
- MessageBox( GetActiveWindow( ), szBuffer, szCaption, MB_OK);
- }
-
- // *** OKCancelMsgBox
- BOOL OKCancelMsgBox( char *szCaption, char *szFormat, ...)
- {
- char szBuffer[256];
- char *pArguments;
- pArguments = (char *)&szFormat + sizeof szFormat;
- vsprintf(szBuffer, szFormat, pArguments);
- int iret = MessageBox( GetActiveWindow( ), szBuffer, szCaption,
- MB_OKCANCEL | MB_ICONQUESTION);
- if ( iret == IDOK ) return TRUE;
- else return FALSE;
- }
-
- // *** HourGlass - toggle hourglass Icon
- void HourGlass(HWND hWnd)
- {
- static HCURSOR hSaveCursor = NULL;
- static hHourGlass = NULL;
- if (hSaveCursor == NULL) // turn on hourglass
- {
- SetCapture(hWnd);
- if (hHourGlass == NULL) hHourGlass = LoadCursor(NULL, IDC_WAIT );
- hSaveCursor = SetCursor(hHourGlass);
- }
- else // turn off hourglass
- {
- SetCursor( hSaveCursor);
- ReleaseCapture();
- hSaveCursor = NULL;
- }
- }
-
- // *** myError
- //error handling function for when CGMWindow being drawn
- void
- myError(const char *inMsg, const char *inMsg2, int errFlag)
- {
- HWND ActiveWindow = CGMWindow::hWindow; // NOTE: GetFocus() doesn't work here
- CgmWindowPt CgmWin = (CgmWindowPt)GetPointer( ActiveWindow ); // invalid value if WM_CREATE not
-
- CgmWin->errors++;
-
- if (!errFlag) // severe error - overwrite any warnings
- {
- CgmWin->severe_error = TRUE;
- // delete any existing error messages
- DeleteSz(CgmWin->ErrMsg1 ); CgmWin->ErrMsg1 = NULL;
- DeleteSz(CgmWin->ErrMsg2 ); CgmWin->ErrMsg2 = NULL;
- }
-
- else // warning - don't overwrite first warnings
- if (CgmWin->ErrMsg1) return; // previous message exists
-
- CgmWin->ErrMsg1 = new char[strlen(inMsg) + 1];
- _fstrcpy(CgmWin->ErrMsg1, inMsg);
- if (inMsg2 && *inMsg2)
- {
- CgmWin->ErrMsg2 = new char[strlen(inMsg2) + 1];
- _fstrcpy(CgmWin->ErrMsg2, inMsg2);
- }
- else { CgmWin->ErrMsg2 = new char; CgmWin->ErrMsg2 =0;}
- }
-
-
-