[project @ 2000-03-22 18:14:22 by sewardj]
[ghc-hetmet.git] / ghc / interpreter / machdep.c
index cbe9d54..cdd1fc4 100644 (file)
@@ -13,8 +13,8 @@
  * included in the distribution.
  *
  * $RCSfile: machdep.c,v $
- * $Revision: 1.16 $
- * $Date: 1999/12/03 14:38:39 $
+ * $Revision: 1.22 $
+ * $Date: 2000/03/22 18:14:22 $
  * ------------------------------------------------------------------------*/
 
 #ifdef HAVE_SIGNAL_H
@@ -45,7 +45,7 @@
 #ifdef HAVE_DOS_H
 # include <dos.h>
 #endif
-#if defined HAVE_CONIO_H && ! HUGS_FOR_WINDOWS
+#if defined HAVE_CONIO_H
 # include <conio.h>
 #endif
 #ifdef HAVE_IO_H
 # include <windows.h>
 #endif
 
-#if HUGS_FOR_WINDOWS
-#include <dir.h>
-#include <mem.h>
-
-extern HCURSOR HandCursor;            /* Forward references to cursors   */
-extern HCURSOR GarbageCursor;
-extern HCURSOR SaveCursor;
-static void    local DrawStatusLine     Args((HWND));
-#endif
-
 #if DOS
 #include <mem.h>
 extern unsigned _stklen = 8000;         /* Allocate an 8k stack segment    */
@@ -118,35 +108,25 @@ int allow_break_count = 0;
 #define HugsRoot ("SOFTWARE\\Haskell\\Hugs\\" HUGS_VERSION "\\")
 #define ProjectRoot ("SOFTWARE\\Haskell\\Projects\\")
 
-static Bool   local createKey      Args((HKEY, String, PHKEY, REGSAM));
-static Bool   local queryValue     Args((HKEY, String, String, LPDWORD, LPBYTE, DWORD));
-static Bool   local setValue       Args((HKEY, String, String, DWORD, LPBYTE, DWORD));
-static String local readRegString  Args((HKEY, String, String, String));
-static Int    local readRegInt     Args((String,Int));
-static Bool   local writeRegString Args((String,String));
-static Bool   local writeRegInt    Args((String,Int));
+static Bool   local createKey      ( HKEY, String, PHKEY, REGSAM );
+static Bool   local queryValue     ( HKEY, String, String, LPDWORD, LPBYTE, DWORD );
+static Bool   local setValue       ( HKEY, String, String, DWORD, LPBYTE, DWORD );
+static String local readRegString  ( HKEY, String, String, String );
+static Int    local readRegInt     ( String,Int );
+static Bool   local writeRegString ( String,String );
+static Bool   local writeRegInt    ( String,Int );
 
-static String local readRegChildStrings Args((HKEY, String, String, Char, String));
+static String local readRegChildStrings ( HKEY, String, String, Char, String );
 #endif /* USE_REGISTRY */
 
 /* --------------------------------------------------------------------------
  * Find information about a file:
  * ------------------------------------------------------------------------*/
 
-#if RISCOS
-typedef struct { unsigned hi, lo; } Time;
-#define timeChanged(now,thn)    (now.hi!=thn.hi || now.lo!=thn.lo)
-#define timeSet(var,tm)         var.hi = tm.hi; var.lo = tm.lo
-error  timeEarlier not defined
-#else
-typedef time_t Time;
-#define timeChanged(now,thn)      (now!=thn)
-#define timeSet(var,tm)           var = tm
-#define timeEarlier(earlier,now)  (earlier < now)
-#endif
+#include "machdep_time.h"
 
-static Bool local readable      Args((String));
-static Void local getFileInfo   Args((String, Time *, Long *));
+static Bool local readable      ( String );
+static Void local getFileInfo   ( String, Time *, Long * );
 
 static Void local getFileInfo(f,tm,sz)  /* find time stamp and size of file*/
 String f;
@@ -241,18 +221,17 @@ String f; {
  * Search for script files on the HUGS path:
  * ------------------------------------------------------------------------*/
 
-static String local hugsdir       Args((Void));
+static String local hugsdir       ( Void );
 #if HSCRIPT
-static String local hscriptDir    Args((Void));
+static String local hscriptDir    ( Void );
 #endif
-//static String local RealPath      Args((String));
-static int    local pathCmp       Args((String, String));
-static String local normPath      Args((String));
-static Void   local searchChr     Args((Int));
-static Void   local searchStr     Args((String));
-static Bool   local tryEndings    Args((String));
-
-#if DOS_FILENAMES
+static int    local pathCmp       ( String, String );
+static String local normPath      ( String );
+static Void   local searchChr     ( Int );
+static Void   local searchStr     ( String );
+static Bool   local tryEndings    ( String );
+
+#if (DOS_FILENAMES || __CYGWIN32__) 
 # define SLASH                   '\\'
 # define isSLASH(c)              ((c)=='\\' || (c)=='/')
 # define PATHSEP                 ';'
@@ -691,7 +670,7 @@ Bool findFilesForModule (
    strcat(augdPath, "lib");
    strcat(augdPath, PATHSEP_STR);
 
-   /* fprintf ( stderr, "augdpath = `%s'\n", augdPath ); */
+   /*   fprintf ( stderr, "augdpath = `%s'\n", augdPath ); */
 
    peEnd = augdPath-1;
    while (1) {
@@ -771,12 +750,49 @@ Bool findFilesForModule (
 }
 
 
+/* If the primaryObjectName is (eg)
+     /foo/bar/PrelSwamp.o
+   and the extraFileName is (eg)
+     swampy_cbits
+   and DLL_ENDING is set to .o
+   return
+     /foo/bar/swampy_cbits.o
+     and set *extraFileSize to its size, or -1 if not avail
+*/
+String getExtraObjectInfo ( String primaryObjectName,
+                            String extraFileName,
+                            Int*   extraFileSize )
+{
+   Time   xTime;
+   Long   xSize;
+   String xtra;
+
+   Int i = strlen(primaryObjectName)-1;
+   while (i >= 0 && primaryObjectName[i] != SLASH) i--;
+   if (i == -1) return extraFileName;
+   i++;
+   xtra = malloc ( i+3+strlen(extraFileName)+strlen(DLL_ENDING) );
+   if (!xtra) internal("deriveExtraObjectName: malloc failed");
+   strncpy ( xtra, primaryObjectName, i );
+   xtra[i] = 0;
+   strcat ( xtra, extraFileName );
+   strcat ( xtra, DLL_ENDING );
+
+   *extraFileSize = -1;
+   if (readable(xtra)) {
+      getFileInfo ( xtra, &xTime, &xSize );
+      *extraFileSize = xSize;
+   }
+   return xtra;
+}
+
+
 /* --------------------------------------------------------------------------
  * Substitute old value of path into empty entries in new path
  * eg substPath("a:b:c::d:e","x:y:z") = "a:b:c:x:y:z:d:e"
  * ------------------------------------------------------------------------*/
 
-static String local substPath Args((String,String));
+static String local substPath ( String,String );
 
 static String local substPath(new,sub) /* substitute sub path into new path*/
 String new;
@@ -814,9 +830,6 @@ String sub; {
 Bool gcMessages = FALSE;                /* TRUE => print GC messages       */
 
 Void gcStarted() {                      /* Notify garbage collector start  */
-#if HUGS_FOR_WINDOWS
-    SaveCursor = SetCursor(GarbageCursor);
-#endif
     if (gcMessages) {
         Printf("{{Gc");
         FlushStdout();
@@ -836,9 +849,6 @@ Int recovered; {
         Printf("%d}}",recovered);
         FlushStdout();
     }
-#if HUGS_FOR_WINDOWS
-    SetCursor(SaveCursor);
-#endif
 }
 
 Cell *CStackBase;                       /* Retain start of C control stack */
@@ -905,7 +915,7 @@ void gcCStack() {
 Void gcCStack() {                       /* Garbage collect elements off    */
     Cell stackTop = NIL;                /* C stack                         */
     Cell *ptr = &stackTop;
-#if SIZEOF_INTP == 2
+#if SIZEOF_VOID_P == 2
     if (((long)(ptr) - (long)(CStackBase))&1)
         fatal("gcCStack");
 #elif STACK_ALIGNMENT == 2 /* eg Macintosh 68000 */
@@ -935,7 +945,7 @@ Void gcCStack() {                       /* Garbage collect elements off    */
     GuessDirection;
 #endif
 
-#if SIZEOF_INTP==4 && STACK_ALIGNMENT == 2 /* eg Macintosh 68000 */
+#if SIZEOF_VOID_P==4 && STACK_ALIGNMENT == 2 /* eg Macintosh 68000 */
     ptr = (Cell *)((long)(&stackTop) + 2);
     StackGrowsDown;
 #endif
@@ -1091,7 +1101,7 @@ Int readTerminalChar() {                /* read character from terminal    */
     if (terminalEchoReqd) {
         return getchar();
     } else {
-#if IS_WIN32 && !HUGS_FOR_WINDOWS && !__BORLANDC__
+#if IS_WIN32 && !__BORLANDC__
        /* When reading a character from the console/terminal, we want
         * to operate in 'raw' mode (to use old UNIX tty parlance) and have
         * it return when a character is available and _not_ wait until
@@ -1159,7 +1169,7 @@ Int readTerminalChar() {                /* read character from terminal    */
 Bool    broken         = FALSE;
 static  Bool breakReqd = FALSE;
 static  sigProto(ignoreBreak);
-static  Void local installHandlers Args((Void));
+static  Void local installHandlers ( Void );
 
 Bool breakOn(reqd)                      /* set break trapping on if reqd,  */
 Bool reqd; {                            /* or off otherwise, returning old */
@@ -1417,9 +1427,9 @@ int snprintf(char* buffer, int count, const char* fmt, ...) {
 
 #define HugsRoot ("SOFTWARE\\Haskell\\Hugs\\" HUGS_VERSION "\\")
 
-static Bool   local createKey      Args((HKEY, PHKEY, REGSAM));
-static Bool   local queryValue     Args((HKEY, String, LPDWORD, LPBYTE, DWORD));
-static Bool   local setValue       Args((HKEY, String, DWORD, LPBYTE, DWORD));
+static Bool   local createKey      ( HKEY, PHKEY, REGSAM );
+static Bool   local queryValue     ( HKEY, String, LPDWORD, LPBYTE, DWORD );
+static Bool   local setValue       ( HKEY, String, DWORD, LPBYTE, DWORD );
 
 static Bool local createKey(hKey, phRootKey, samDesired)
 HKEY    hKey;
@@ -1543,17 +1553,12 @@ Void machdep(what)                      /* Handle machine specific         */
 Int what; {                             /* initialisation etc..            */
     switch (what) {
         case MARK    : break;
-        case INSTALL : installHandlers();
+        case POSTPREL: break;
+        case PREPREL : installHandlers();
                        break;
         case RESET   :
         case BREAK   :
         case EXIT    : normalTerminal();
-#if HUGS_FOR_WINDOWS
-                       if (what==EXIT)
-                           DestroyWindow(hWndMain);
-                       else
-                           SetCursor(LoadCursor(NULL,IDC_ARROW));
-#endif
                        break;
     }
 }