X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=inline;f=ghc%2Finterpreter%2Fmachdep.c;h=158fcf6eaacecdabfd1ab8bfeca2bdf69de0bd49;hb=f6af472e5394338ca7f663263f189b7336f918cb;hp=823b5b7a71c2b8acf46bcda016b9750b6044902c;hpb=f88ac43f881583ec611edeafbb9e68419ba7ef4b;p=ghc-hetmet.git diff --git a/ghc/interpreter/machdep.c b/ghc/interpreter/machdep.c index 823b5b7..158fcf6 100644 --- a/ghc/interpreter/machdep.c +++ b/ghc/interpreter/machdep.c @@ -13,8 +13,8 @@ * included in the distribution. * * $RCSfile: machdep.c,v $ - * $Revision: 1.20 $ - * $Date: 2000/03/13 11:37:16 $ + * $Revision: 1.31 $ + * $Date: 2000/05/10 16:51:52 $ * ------------------------------------------------------------------------*/ #ifdef HAVE_SIGNAL_H @@ -45,7 +45,7 @@ #ifdef HAVE_DOS_H # include #endif -#if defined HAVE_CONIO_H && ! HUGS_FOR_WINDOWS +#if defined HAVE_CONIO_H # include #endif #ifdef HAVE_IO_H @@ -58,16 +58,6 @@ # include #endif -#if HUGS_FOR_WINDOWS -#include -#include - -extern HCURSOR HandCursor; /* Forward references to cursors */ -extern HCURSOR GarbageCursor; -extern HCURSOR SaveCursor; -static void local DrawStatusLine ( HWND ); -#endif - #if DOS #include extern unsigned _stklen = 8000; /* Allocate an 8k stack segment */ @@ -105,45 +95,10 @@ int allow_break_count = 0; #endif /* -------------------------------------------------------------------------- - * Prototypes for registry reading - * ------------------------------------------------------------------------*/ - -#if USE_REGISTRY - -/* where have we hidden things in the registry? */ -#if HSCRIPT -#define HScriptRoot ("SOFTWARE\\Haskell\\HaskellScript\\") -#endif - -#define HugsRoot ("SOFTWARE\\Haskell\\Hugs\\" HUGS_VERSION "\\") -#define ProjectRoot ("SOFTWARE\\Haskell\\Projects\\") - -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 ( 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 ( String ); static Void local getFileInfo ( String, Time *, Long * ); @@ -251,12 +206,13 @@ static Void local searchChr ( Int ); static Void local searchStr ( String ); static Bool local tryEndings ( String ); -#if DOS_FILENAMES -# define SLASH '\\' +#if (DOS_FILENAMES || __CYGWIN32__) +# define SLASH '/' +# define SLASH_STR "/" # define isSLASH(c) ((c)=='\\' || (c)=='/') # define PATHSEP ';' # define PATHSEP_STR ";" -# define DLL_ENDING ".dll" +# define DLL_ENDING ".u_o" #elif MAC_FILENAMES # define SLASH ':' # define isSLASH(c) ((c)==SLASH) @@ -266,6 +222,7 @@ static Bool local tryEndings ( String ); # define DLL_ENDING ".pef" #else # define SLASH '/' +# define SLASH_STR "/" # define isSLASH(c) ((c)==SLASH) # define PATHSEP ':' # define PATHSEP_STR ":" @@ -520,14 +477,6 @@ String along; /* Return NULL if file does not exist */ String nm; { /* AC, 1/21/99: modified to search hugsPath first, then projectPath */ String s = findMPathname(along,nm,hugsPath); -#if USE_REGISTRY -#if 0 - ToDo: - if (s==NULL) { - s = findMPathname(along,nm,projectPath); - } -#endif /* 0 */ -#endif /* USE_REGISTRY */ return s ? s : normPath(searchBuf); } @@ -644,9 +593,8 @@ Bool findFilesForModule ( String modName, String* path, String* sExt, - Bool* sAvail, Time* sTime, Long* sSize, - Bool* iAvail, Time* iTime, Long* iSize, - Bool* oAvail, Time* oTime, Long* oSize + Bool* sAvail, Time* sTime, Long* sSize, + Bool* oiAvail, Time* oiTime, Long* oSize, Long* iSize ) { /* Let the module name given be M. @@ -658,31 +606,36 @@ Bool findFilesForModule ( use P to fill in the path names. Otherwise, move on to the next path entry. If all path entries are exhausted, return False. + + If in standalone, only look for (and succeed for) source modules. + Caller free()s path. sExt is statically allocated. + srcExt is only set if a valid source file is found. */ Int nPath; Bool literate; String peStart, peEnd; - String augdPath; /* .:hugsPath:installDir/GhcPrel:installDir/lib */ + String augdPath; /* .:hugsPath:installDir/../lib/std:installDir/lib */ + Time oTime, iTime; + Bool oAvail, iAvail; *path = *sExt = NULL; - *sAvail = *iAvail = *oAvail = FALSE; - *sSize = *iSize = *oSize = 0; + *sAvail = *oiAvail = oAvail = iAvail = FALSE; + *sSize = *oSize = *iSize = 0; augdPath = malloc( 2*(10+3+strlen(installDir)) - +strlen(hugsPath) +10/*paranoia*/); + +strlen(hugsPath) +50/*paranoia*/); if (!augdPath) internal("moduleNameToFileNames: malloc failed(2)"); augdPath[0] = 0; - strcat(augdPath, "."); - strcat(augdPath, PATHSEP_STR); - - strcat(augdPath, hugsPath); - strcat(augdPath, PATHSEP_STR); if (combined) { strcat(augdPath, installDir); - strcat(augdPath, "GhcPrel"); + strcat(augdPath, ".."); + strcat(augdPath, SLASH_STR); + strcat(augdPath, "lib"); + strcat(augdPath, SLASH_STR); + strcat(augdPath, "std"); strcat(augdPath, PATHSEP_STR); } @@ -690,6 +643,13 @@ Bool findFilesForModule ( strcat(augdPath, "lib"); strcat(augdPath, PATHSEP_STR); + /* these two were previously before the above `if' */ + strcat(augdPath, "."); + strcat(augdPath, PATHSEP_STR); + + strcat(augdPath, hugsPath); + strcat(augdPath, PATHSEP_STR); + /* fprintf ( stderr, "augdpath = `%s'\n", augdPath ); */ peEnd = augdPath-1; @@ -721,20 +681,25 @@ Bool findFilesForModule ( nPath += strlen(modName); /* searchBuf now holds 'P/M'. Try out the various endings. */ - *path = *sExt = NULL; - *sAvail = *iAvail = *oAvail = FALSE; - *sSize = *iSize = *oSize = 0; - - strcpy(searchBuf+nPath, DLL_ENDING); - if (readable(searchBuf)) { - *oAvail = TRUE; - getFileInfo(searchBuf, oTime, oSize); - } + *path = *sExt = NULL; + *sAvail = *oiAvail = oAvail = iAvail = FALSE; + *sSize = *oSize = *iSize = 0; - strcpy(searchBuf+nPath, ".u_hi"); - if (readable(searchBuf)) { - *iAvail = TRUE; - getFileInfo(searchBuf, iTime, iSize); + if (combined) { + strcpy(searchBuf+nPath, DLL_ENDING); + if (readable(searchBuf)) { + oAvail = TRUE; + getFileInfo(searchBuf, &oTime, oSize); + } + strcpy(searchBuf+nPath, HI_ENDING); + if (readable(searchBuf)) { + iAvail = TRUE; + getFileInfo(searchBuf, &iTime, iSize); + } + if (oAvail && iAvail) { + *oiAvail = TRUE; + *oiTime = whicheverIsLater ( oTime, iTime ); + } } strcpy(searchBuf+nPath, ".hs"); @@ -754,7 +719,7 @@ Bool findFilesForModule ( } /* Success? */ - if (*sAvail || (*oAvail && *iAvail)) { + if (*sAvail || *oiAvail) { nPath -= strlen(modName); *path = malloc(nPath+1); if (!(*path)) @@ -770,7 +735,7 @@ Bool findFilesForModule ( } -/* If the primaryObjectName for is (eg) +/* If the primaryObjectName is (eg) /foo/bar/PrelSwamp.o and the extraFileName is (eg) swampy_cbits @@ -850,9 +815,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(); @@ -872,9 +834,6 @@ Int recovered; { Printf("%d}}",recovered); FlushStdout(); } -#if HUGS_FOR_WINDOWS - SetCursor(SaveCursor); -#endif } Cell *CStackBase; /* Retain start of C control stack */ @@ -952,7 +911,7 @@ Void gcCStack() { /* Garbage collect elements off */ fatal("gcCStack"); #endif -#define Blargh markWithoutMove(*ptr); +#define Blargh mark(*ptr); #if 0 markWithoutMove((*ptr)/sizeof(Cell)); \ markWithoutMove(( (void*)(*ptr)-(void*)heapTopFst)/sizeof(Cell)); \ @@ -1127,7 +1086,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 @@ -1192,66 +1151,10 @@ Int readTerminalChar() { /* read character from terminal */ * Interrupt handling: * ------------------------------------------------------------------------*/ -Bool broken = FALSE; -static Bool breakReqd = FALSE; -static sigProto(ignoreBreak); -static Void local installHandlers ( Void ); - -Bool breakOn(reqd) /* set break trapping on if reqd, */ -Bool reqd; { /* or off otherwise, returning old */ - Bool old = breakReqd; - - breakReqd = reqd; - if (reqd) { - if (broken) { /* repond to break signal received */ - broken = FALSE; /* whilst break trap disabled */ - sigRaise(breakHandler); - /* not reached */ - } -#if HANDLERS_CANT_LONGJMP - ctrlbrk(ignoreBreak); -#else - ctrlbrk(breakHandler); -#endif - } else { - ctrlbrk(ignoreBreak); - } - return old; -} - -static sigHandler(ignoreBreak) { /* record but don't respond to break*/ - ctrlbrk(ignoreBreak); /* reinstall signal handler */ - /* redundant on BSD systems but essential */ - /* on POSIX and other systems */ - broken = TRUE; - interruptStgRts(); - sigResume; -} - -#if !DONT_PANIC -static sigProto(panic); -static sigHandler(panic) { /* exit in a panic, on receipt of */ - everybody(EXIT); /* an unexpected signal */ - fprintf(stderr,"\nUnexpected signal\n"); - exit(1); - sigResume;/*NOTREACHED*/ -} -#endif /* !DONT_PANIC */ - -#if IS_WIN32 -BOOL WINAPI consoleHandler(DWORD dwCtrlType) { - switch (dwCtrlType) { /* Allows Hugs to be terminated */ - case CTRL_CLOSE_EVENT : /* from the window's close menu. */ - ExitProcess(0); - } - return FALSE; -} -#endif - -static Void local installHandlers() { /* Install handlers for all fatal */ +static Void installHandlers ( void ) { /* Install handlers for all fatal */ /* signals except SIGINT and SIGBREAK*/ #if IS_WIN32 - SetConsoleCtrlHandler(consoleHandler,TRUE); + /* SetConsoleCtrlHandler(consoleHandler,TRUE); */ #endif #if !DONT_PANIC && !DOS # ifdef SIGABRT @@ -1440,124 +1343,6 @@ int snprintf(char* buffer, int count, const char* fmt, ...) { #endif /* HAVE_SNPRINTF */ /* -------------------------------------------------------------------------- - * Read/write values from/to the registry - * - * All reads are from either HUGS_CURRENT_USER\\hugs_ROOT\\key or - * HUGS_LOCAL_MACHINE\\hugs_ROOT\\key. (Machine entry is only used if - * user entry doesn't exist). - * - * All writes are to HUGS_CURRENT_USER\\HugsRoot\\key - * ------------------------------------------------------------------------*/ - -#if USE_REGISTRY - -#define HugsRoot ("SOFTWARE\\Haskell\\Hugs\\" HUGS_VERSION "\\") - -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; -PHKEY phRootKey; -REGSAM samDesired; { - DWORD dwDisp; - return RegCreateKeyEx(hKey, HugsRoot, - 0, "", REG_OPTION_NON_VOLATILE, - samDesired, NULL, phRootKey, &dwDisp) - == ERROR_SUCCESS; -} - -static Bool local queryValue(hKey, regPath, var, type, buf, bufSize) -HKEY hKey; -String regPath; -String var; -LPDWORD type; -LPBYTE buf; -DWORD bufSize; { - HKEY hRootKey; - - if (!createKey(hKey, regPath, &hRootKey, KEY_READ)) { - return FALSE; - } else { - LONG res = RegQueryValueEx(hRootKey, var, NULL, type, buf, &bufSize); - RegCloseKey(hRootKey); - return (res == ERROR_SUCCESS); - } -} - -static Bool local setValue(hKey, regPath, var, type, buf, bufSize) -HKEY hKey; -String regPath; -String var; -DWORD type; -LPBYTE buf; -DWORD bufSize; { - HKEY hRootKey; - - if (!createKey(hKey, regPath, &hRootKey, KEY_WRITE)) { - return FALSE; - } else { - LONG res = RegSetValueEx(hRootKey, var, 0, type, buf, bufSize); - RegCloseKey(hRootKey); - return (res == ERROR_SUCCESS); - } -} - -static String local readRegString(key,regPath,var,def) /* read String from registry */ -HKEY key; -String regPath; -String var; -String def; { - static char buf[300]; - DWORD type; - if (queryValue(key, regPath,var, &type, buf, sizeof(buf)) - && type == REG_SZ) { - return (String)buf; - } else { - return def; - } -} - -static Int local readRegInt(var, def) /* read Int from registry */ -String var; -Int def; { - DWORD buf; - DWORD type; - - if (queryValue(HKEY_CURRENT_USER, HugsRoot, var, &type, - (LPBYTE)&buf, sizeof(buf)) - && type == REG_DWORD) { - return (Int)buf; - } else if (queryValue(HKEY_LOCAL_MACHINE, HugsRoot, var, &type, - (LPBYTE)&buf, sizeof(buf)) - && type == REG_DWORD) { - return (Int)buf; - } else { - return def; - } -} - -static Bool local writeRegString(var,val) /* write String to registry */ -String var; -String val; { - if (NULL == val) { - val = ""; - } - return setValue(HKEY_CURRENT_USER, HugsRoot, var, - REG_SZ, (LPBYTE)val, lstrlen(val)+1); -} - -static Bool local writeRegInt(var,val) /* write String to registry */ -String var; -Int val; { - return setValue(HKEY_CURRENT_USER, HugsRoot, var, - REG_DWORD, (LPBYTE)&val, sizeof(val)); -} - -#endif /* USE_REGISTRY */ - -/* -------------------------------------------------------------------------- * Things to do with the argv/argc and the env * ------------------------------------------------------------------------*/ @@ -1585,12 +1370,6 @@ Int what; { /* initialisation etc.. */ case RESET : case BREAK : case EXIT : normalTerminal(); -#if HUGS_FOR_WINDOWS - if (what==EXIT) - DestroyWindow(hWndMain); - else - SetCursor(LoadCursor(NULL,IDC_ARROW)); -#endif break; } }