void MDIOWinTop_Init (BOOL pmStopUserClose) { char myButtonBarWindowClassName [256]; int myResult; WNDCLASSEX myWindowClass; stStopUserClose = pmStopUserClose; // Get the background brush stBackgroundBrush = CreateSolidBrush (GetSysColor (COLOR_BTNFACE)); if (stBackgroundBrush == NULL) { EdInt_HaltEnvironment (IDS_MIO_CREATEBRUSHFAIL, __FILE__, __LINE__, GetLastError ()); } // Get the class name EdInt_LoadString (IDS_MIOWINDOWTOP_WINDOW_NAME, myButtonBarWindowClassName, sizeof (myButtonBarWindowClassName)); // // Register the status window class // myWindowClass.cbSize = sizeof (myWindowClass); // Set window class to redraw when window size changes myWindowClass.style = CS_HREDRAW | CS_VREDRAW; // Procedure to be called with messages for this window class myWindowClass.lpfnWndProc = MyButtonBarWindowProcedure; // The extra space in class struct myWindowClass.cbClsExtra = 0; // The extra space in window struct for the pointer to text data // and editor window myWindowClass.cbWndExtra = WINDOW_EXTRA_MEMORY; // The application's handle myWindowClass.hInstance = MIO_applicationInstance; // Set the icon for this window class myWindowClass.hIcon = NULL; // Set the cursor for this window class myWindowClass.hCursor = LoadCursor (NULL, IDC_ARROW); // Set the background colour for this window myWindowClass.hbrBackground = stBackgroundBrush; // Set the menu for this window class myWindowClass.lpszMenuName = NULL; // Name of the window class myWindowClass.lpszClassName = myButtonBarWindowClassName; // Set the icon for this class. myWindowClass.hIconSm = NULL; myResult = RegisterClassEx (&myWindowClass); if (myResult == 0) { EdInt_HaltEnvironment (IDS_MIO_REGISTERCLASSFAIL, __FILE__, __LINE__, GetLastError ()); } } // MDIOWinTop_Init
static BOOL MySetDialogFont (HWND pmButtonBarWindow) { char myFontName [256]; HDC myDisplayContext; TEXTMETRIC myTextMetrics; // Get the font name EdInt_LoadString (IDS_MIO_DIALOG_FONT_NAME, myFontName, sizeof (myFontName)); // Delete any previously existing font if (stButtonFont != NULL) { DeleteObject (stButtonFont); } // Create the new font stButtonFont = EdInt_CreateFont (pmButtonBarWindow, myFontName, stProperties.dialogFontSize, NO_BOLD, NO_ITALIC); if (stButtonFont == NULL) { EdInt_HaltEnvironment (IDS_MIO_CREATEFONTFAIL, __FILE__, __LINE__, GetLastError ()); return FALSE; } myDisplayContext = GetDC (pmButtonBarWindow); SelectFont (myDisplayContext, stButtonFont); GetTextMetrics (myDisplayContext, &myTextMetrics); stButtonFontCharHeight = myTextMetrics.tmHeight; stButtonFontCharWidth = myTextMetrics.tmAveCharWidth; ReleaseDC (pmButtonBarWindow, myDisplayContext); return TRUE; } // MySetDialogFont
void MIOFile_SetExecutionDirectory (const char *pmExecutionDir) { int myPathType; if (!MyConvertToTuringPath (pmExecutionDir, stExecutionDir, &myPathType)) { EdInt_HaltEnvironment (IDS_MIO_FILEFAIL, __FILE__, __LINE__, 0, 201); } if ((myPathType & ABSOLUTE_PATH) == 0) { EdInt_HaltEnvironment (IDS_MIO_FILEFAIL, __FILE__, __LINE__, 0, 202); } if (stExecutionDir [strlen (stExecutionDir) - 1] != PATH_SEP) { strcat (stExecutionDir, PATH_SEP_STR); } } // MIOFile_SetCurrentDirectory
static ButtonBarWindowInfoPtr MyGetButtonBarWindowInfo ( HWND pmButtonBarWindow) { int myWindowType; ButtonBarWindowInfoPtr myInfo; myWindowType = GetWindowLong (pmButtonBarWindow, WINDOW_MEM_WINDOW_TYPE); if (myWindowType != WINDOW_TYPE_BEGINNER_TOP) { EdInt_HaltEnvironment (IDS_MIO_BADWINDOWTYPE, __FILE__, __LINE__, 0, myWindowType, WINDOW_TYPE_BEGINNER_TOP); } myInfo = (ButtonBarWindowInfoPtr) GetWindowLong (pmButtonBarWindow, WINDOW_MEM_WINDOW_INFO); if (myInfo == NULL) { EdInt_HaltEnvironment (IDS_MIO_GETWINDOWLONGFAIL, __FILE__, __LINE__, GetLastError (), WINDOW_MEM_WINDOW_INFO); } return myInfo; } // MyGetButtonBarWindowInfo
void MIOFile_Init (int pmOS, const char *pmOOTDir, const char *pmHomeDir) { int myPathType; stOS = pmOS; #if 0 if (!MyConvertToTuringPath (pmOOTDir, stOOTDir, &myPathType)) { EdInt_HaltEnvironment (IDS_MIO_FILEFAIL_1, __FILE__, __LINE__, 0, 101, pmOOTDir, stOOTDir, myPathType); } if ((myPathType & ABSOLUTE_PATH) == 0) { EdInt_HaltEnvironment (IDS_MIO_FILEFAIL_1, __FILE__, __LINE__, 0, 102, pmOOTDir, stOOTDir, myPathType); } if (stOOTDir [strlen (stOOTDir) - 1] != PATH_SEP) { strcat (stOOTDir, PATH_SEP_STR); } if (!MyConvertToTuringPath (pmHomeDir, stHomeDir, &myPathType)) { EdInt_HaltEnvironment (IDS_MIO_FILEFAIL_1, __FILE__, __LINE__, 0, 103, pmHomeDir, stHomeDir, myPathType); } if ((myPathType & ABSOLUTE_PATH) == 0) { EdInt_HaltEnvironment (IDS_MIO_FILEFAIL_1, __FILE__, __LINE__, 0, 104, pmHomeDir, stHomeDir, myPathType); } if (stHomeDir [strlen (stHomeDir) - 1] != PATH_SEP) { strcat (stHomeDir, PATH_SEP_STR); } #endif } // MIOFile_Init
BOOL MIOFile_ConvertPath (const char *pmMDUserPath, char *pmAbsolutePath, char *pmMDAbsolutePath, BOOL pmAllowTrailingSlash) { char myTuringUserPath [4096]; int myPathType; char myPath [4096], myAbsolutePath [4096]; char *myPtr, *myStart, *myDestPtr; // Note that a Turing Path is UNIX like if (!MyConvertToTuringPath (pmMDUserPath, myTuringUserPath, &myPathType)) { return FALSE; } if ((stOS != OS_WINDOWS) && (myPathType & WINDOWS_TYPE_PATH)) { SET_ERRMSG (E_FSYS_MALFORMED_PATHNAME, "Attempt to use a Windows style pathname (%s) on a " "non-Windows system", pmMDUserPath); return FALSE; } if ((stOS != OS_MACOS) && (myPathType & MACOS_TYPE_PATH)) { SET_ERRMSG (E_FSYS_MALFORMED_PATHNAME, "Attempt to use a Macintosh style pathname (%s) on a " "non-Macintosh system", pmMDUserPath); return FALSE; } // // There are a number of different file types possible at this point, // each with different flags: // // RELATIVE_PATH "a/b/c" // ABSOLUTE_PATH "%oot/a/b/c" // ABSOLUTE_NO_VOL_PATH "/a/b/c" (Win/Mac assume default vol) // ABSOLUTE_PATH [WINDOWS] "x:/a/b/c" // ABSOLUTE_PATH [WINDOWS] "//server/a/b/c" // ABSOLUTE_PATH [MACOS] "volume:/a/b/c" // ABSOLUTE_NO_DIR_PATH [WINDOWS] "x:" (Win assume default directory) // if (myPathType & RELATIVE_PATH) { // // RELATIVE_PATH "a/b/c" // strcpy (myPath, stExecutionDir); // Add the relative directory strcat (myPath, myTuringUserPath); } else { if ((strncmp (myTuringUserPath, "%oot", 4) == 0) || (strncmp (myTuringUserPath, "%home", 5) == 0)) { // // ABSOLUTE_PATH "%oot/a/b/c" // if (strcmp (myTuringUserPath, "%oot") == 0) { strcpy (myPath, stOOTDir); } else if (strcmp (myTuringUserPath, "%home") == 0) { strcpy (myPath, stHomeDir); } else if (strncmp (myTuringUserPath, "%oot/", 5) == 0) { strcpy (myPath, stOOTDir); strcat (myPath, &myTuringUserPath [5]); } else if (strncmp (myTuringUserPath, "%home/", 6) == 0) { strcpy (myPath, stHomeDir); strcat (myPath, &myTuringUserPath [6]); } else { EdInt_HaltEnvironment (IDS_MIO_FILEFAIL, __FILE__, __LINE__, 0, 401); } } else if (myPathType & ABSOLUTE_NO_VOL_PATH) { // // ABSOLUTE_NO_VOL_PATH "/a/b/c" (Win/Mac assume default vol) // if (stOS == OS_UNIXLIKE) { EdInt_HaltEnvironment (IDS_MIO_FILEFAIL, __FILE__, __LINE__, 0, 402); } // Copy the volume name from the execution directory strcpy (myPath, stExecutionDir); myPtr = myPath; while ((*myPtr != ':') && (*myPtr != 0)) { myPtr++; } if (*myPtr == 0) { EdInt_HaltEnvironment (IDS_MIO_FILEFAIL, __FILE__, __LINE__, 0, 403); } // Copy the user path after the execution directory volume myPtr++; strcpy (myPtr, myTuringUserPath); } else if (myPathType & ABSOLUTE_NO_DIR_PATH) { // // ABSOLUTE_NO_DIR_PATH [WINDOWS] "x:" (Win assume default directory) // if (stOS != OS_WINDOWS) { EdInt_HaltEnvironment (IDS_MIO_FILEFAIL, __FILE__, __LINE__, 0, 404); } if (!MDIOFile_GetDefaultPathForWindowsVolume (myTuringUserPath [0], myPath)) { // Error message is set by MDIOFile_GetDefault... return FALSE; } } else { // // We don't actually have to do any additional work for the // following. // // ABSOLUTE_PATH [WINDOWS] "x:/a/b/c" // ABSOLUTE_PATH [WINDOWS] "//server/a/b/c" // ABSOLUTE_PATH [MACOS] "volume:/a/b/c" // strcpy (myPath, myTuringUserPath); } } // // myPath is now in one of the following forms: // /a/b/c" (UNIX only) [/] // "x:/a/b/c" (WINDOWS only) [x:/] // "//server/share/a/b/c" (WINDOWS only) [//server/share/] // "volume:/a/b/c" (MACOS only) [volume:/] // // First, mark where the start of the path is // if ((myPath [0] == PATH_SEP) && (myPath [1] == PATH_SEP)) { myPtr = &myPath [2]; // myPtr now points at beginning of server name // Skip over server name while ((*myPtr != PATH_SEP) && (*myPtr != 0)) { myPtr++; } if (*myPtr == 0) { EdInt_HaltEnvironment (IDS_MIO_FILEFAIL, __FILE__, __LINE__, 0, 405); } // Skip over share name myPtr++; // myPtr now points at beginning of share name while ((*myPtr != PATH_SEP) && (*myPtr != 0)) { myPtr++; } } else if (myPath [0] == PATH_SEP) { myPtr = myPath; } else { myPtr = myPath; // Skip over volume name while ((*myPtr != ':') && (*myPtr != 0)) { myPtr++; } if (*myPtr == 0) { EdInt_HaltEnvironment (IDS_MIO_FILEFAIL, __FILE__, __LINE__, 0, 406); } myPtr++; } if (*myPtr == 0) { EdInt_HaltEnvironment (IDS_MIO_FILEFAIL, __FILE__, __LINE__, 0, 407); } myPtr++; // myPtr is now pointing at ^ [//server/share/^ or d:/^] strncpy (myAbsolutePath, myPath, myPtr - myPath); myStart = &myAbsolutePath [myPtr - myPath]; myDestPtr = myStart; // Now factor out the ".."'s while (*myPtr != 0) { if ((strncmp (myPtr, "../", 3) == 0) || (strcmp (myPtr, "..") == 0)) { // // Handle ".." // // Remove directory and last / if (myDestPtr == myStart) { SET_ERRMSG (E_FSYS_MALFORMED_PATHNAME, "Attempt to move up ('..') in the root directory ('%s')", pmMDUserPath); return FALSE; } else { myDestPtr--; do { myDestPtr--; } while (*myDestPtr != PATH_SEP); myDestPtr++; } // Skip over '..' if (strncmp (myPtr, "../", 3) == 0) { myPtr += 3; } else { // Special case: if ".." at the end of the line, we don't want // to end with a /, *unless* we're at the root. *sigh*. myPtr += 2; if (myDestPtr != myStart) { myDestPtr--; } } } else if ((strncmp (myPtr, "./", 2) == 0) || (strcmp (myPtr, ".") == 0)) { // // Handle "." // if (strncmp (myPtr, "./", 2) == 0) { myPtr += 2; } else { // Special case: if "." at the end of the line, we don't want // to end with a /, *unless* we're at the root. *sigh*. myPtr += 1; if (myDestPtr != myStart) { myDestPtr--; } } } else { // // Handle path element // if (*myPtr == PATH_SEP) { SET_ERRMSG (E_FSYS_MALFORMED_PATHNAME, "'//' not allowed in path name (%s)", myAbsolutePath); return FALSE; } while ((*myPtr != PATH_SEP) && (*myPtr != 0)) { *myDestPtr++ = *myPtr++; } } if (*myPtr == PATH_SEP) { *myDestPtr++ = *myPtr++; } } // while (*myPtr != 0) *myDestPtr = 0; // Remove any trailing "/" unless it's the root directory slash myDestPtr--; if ((*myDestPtr == PATH_SEP) && (myDestPtr > myStart)) { if (pmAllowTrailingSlash) { *myDestPtr = 0; } else { SET_ERRMSG (E_FSYS_MALFORMED_PATHNAME, "No trailing slash allowed in a file path name", myAbsolutePath); return FALSE; } } // // At this point we have a Turing style absolute path in myAbsolutePath // // Copy to pmAbsolutePath if necessary if (pmAbsolutePath != NULL) { strcpy (pmAbsolutePath, myAbsolutePath); } // If we don't need an MD absolute path, exit. if (pmMDAbsolutePath == NULL) { return TRUE; } if (stOS == OS_UNIXLIKE) { strcpy (pmMDAbsolutePath, myAbsolutePath); } else if (stOS == OS_WINDOWS) { strcpy (pmMDAbsolutePath, myAbsolutePath); myPtr = pmMDAbsolutePath; while (*myPtr != 0) { if (*myPtr == PATH_SEP) { *myPtr = '\\'; } myPtr++; } } else if (stOS == OS_MACOS) { // TW Work to do here } else { EdInt_HaltEnvironment (IDS_MIO_FILEFAIL, __FILE__, __LINE__, 0, 301); } return TRUE; } // MIOFile_ConvertPath