Some bug fixes for the January release
Pepe Gallardo
pepeg@lcc.uma.es
Tue, 6 Feb 2001 13:05:46 +0100
Here are some bug fixes to the January release of Hugs
****************************************************************************
****
*** BUG ***: HugsHood crashes if the user does not input a valid command
Change the definition of brkCmds in src\hugs.c to this one
****************************************************************************
****
static struct cmd brkCmds[] =
{ {"p", BRK_DISPLAY}
, {"c", BRK_CONTINUE}
, {"s", BRK_SET}
, {"r", BRK_RESET}
, {0,0}
};
****************************************************************************
****
*** BUG ***: The open file dialog in winhugs does not take into account the
current dir.
Change the GetaFileName function in src\winhugs\winhugs.c to this one
****************************************************************************
****
static CHAR* local GetaFileName(HWND hWnd, UINT Mask)
{
#define MAXEXTENSIONS 15
static CHAR Extensions[MAXEXTENSIONS][_MAX_EXT+1];
static OPENFILENAME ofn;
static CHAR szFileName[_MAX_PATH];
CHAR szFile[_MAX_PATH], szFileTitle[_MAX_PATH];
UINT i, j, cbString, n;
CHAR chReplace; /* Separator between different filters in szFilter
*/
CHAR szFilter[300];
char currentDir[_MAX_PATH];
szFile[0] = '\0';
if ((cbString = LoadString(hThisInstance, Mask,
szFilter, sizeof(szFilter))) == 0) {
/* Error */
return NULL;
}
chReplace = szFilter[cbString - 1]; /* Get separator */
/* Get valid extensions for files */
for (n=0, i=0;szFilter[i];) {
while (szFilter[i] != chReplace) i++;
i++;
do {
while (szFilter[i] != '.') i++;
i++;
j=0;
while ((szFilter[i] != ';')&&(szFilter[i] != chReplace)){
Extensions[n][j++] = szFilter[i++];
}
Extensions[n++][j] = (CHAR) 0;
} while (szFilter[i] == ';');
i++;
}
for (;n<MAXEXTENSIONS;n++)
Extensions[n][0] = (CHAR)0;
/* Replace separator with NULL */
for (i = 0; szFilter[i] != '\0'; i++) {
if (szFilter[i] == chReplace)
szFilter[i] = '\0';
}
memset(&ofn, 0, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hInstance = hThisInstance;
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = szFilter;
ofn.nFilterIndex = 1;
ofn.lpstrFile= szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = sizeof(szFileTitle);
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
OFN_ENABLEHOOK | OFN_EXPLORER;;
ofn.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance((FARPROC) FileOpenHookProc,
hThisInstance);
GetCurrentDirectory(_MAX_PATH,currentDir);
ofn.lpstrInitialDir = currentDir;
if (GetOpenFileName(&ofn)) {
strcpy(szFileName, ofn.lpstrFile);
return szFileName;
}
else {
return NULL;
}
}
****************************************************************************
****
*** BUG ***: The script manager does not work well when a file is removed
Change the ScriptManDlgProc function in src\winhugs\winhugs.c to this one
****************************************************************************
****
LRESULT CALLBACK ScriptManDlgProc(HWND hDlg, UINT msg,
WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG: {
Int i;
smLoaded = numScripts;
smUpto = 0;
CenterDialogInParent(hDlg);
SetDialogFont (hDlg, hDialogFont);
SendDlgItemMessage(hDlg, LB_SCRIPTS, LB_SETHORIZONTALEXTENT,
(WPARAM)1000, 0L);
SendDlgItemMessage(hDlg, LB_SCRIPTS, WM_SETREDRAW,FALSE,0L);
for (i=0; i<namesUpto; i++)
SmAddScr(hDlg,scriptReal[i]);
SmSelScr(hDlg,0);
SendDlgItemMessage(hDlg,LB_SCRIPTS,LB_SETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg,LB_SCRIPTS,WM_SETREDRAW,TRUE,0L);
return TRUE;
}
case WM_PAINT: {
HDC hDC;
PAINTSTRUCT Ps;
HBITMAP hBitmap;
RECT aRect, DlgRect;
BeginPaint(hDlg, &Ps);
hDC = Ps.hdc;
/* Paint classes Bitmap */
GetWindowRect(hDlg, &DlgRect);
GetWindowRect(GetDlgItem(hDlg, ID_PLACEBITMAP), &aRect);
hBitmap = LoadMappedBitmap(hThisInstance, "SCRIPTMANDLGBMP");
DrawBitmap(hDC, hBitmap,
aRect.left-DlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),
aRect.top-DlgRect.top-GetSystemMetrics(SM_CYDLGFRAME)-GetSystemMetrics(SM_CY
CAPTION));
DeleteObject(hBitmap);
EndPaint(hDlg, &Ps);
}
break;
case WM_COMMAND:
switch (CMDitem(wParam,lParam)) {
case ID_ADDSCRIPT:
if (smUpto>=NUM_SCRIPTS)
MessageBox(hDlg,"Too many script files",
"Add script", MB_ICONEXCLAMATION|MB_OK);
else {
String s = GetaFileName(hDlg,IDS_FILTERFILE);
if (s)
SmAddScr(hDlg,s);
}
return TRUE;
case ID_DELSCRIPT:
if (selScr < 0)
MessageBox(hDlg,"No script file selected",
"Remove script", MB_ICONEXCLAMATION|MB_OK);
else if (selScr == 0)
MessageBox(hDlg,"Cannot remove prelude file",
"Remove script", MB_ICONEXCLAMATION|MB_OK);
else {
Int i;
SendDlgItemMessage(hDlg, LB_SCRIPTS, LB_DELETESTRING,
selScr, 0L);
if (selScr<smLoaded)
smLoaded = selScr;
if (smFile[selScr]) {
free(smFile[selScr]);
smFile[selScr] = 0;
}
for (i=selScr+1; i<smUpto; ++i)
smFile[i-1] = smFile[i];
smUpto--;
SmSelScr(hDlg,-1);
}
return TRUE;
case ID_EDITSCRIPT:
if (selScr >= 0)
DlgSendMessage(hDlg, WM_COMMAND, LB_SCRIPTS, MAKELONG(0,
LBN_DBLCLK));
else
MessageBox(hDlg,"No file selected","Edit",
MB_ICONEXCLAMATION|MB_OK);
return TRUE;
case ID_CLEARSCRIPTS: {
Int i;
for (i=1; i<smUpto; ++i)
if (smFile[i])
free(smFile[i]);
smUpto = smLoaded = 1;
SendDlgItemMessage(hDlg,LB_SCRIPTS,LB_RESETCONTENT,0,0L);
fprintf(stdstr,"%s\n",smFile[0]);
SendDlgItemMessage(hDlg, LB_SCRIPTS, LB_ADDSTRING, 0,
(LONG) (LPSTR) stdstrbuff);
SmSelScr(hDlg,-1);
return TRUE;
}
case LB_SCRIPTS:
switch (CMDdata(wParam,lParam)) {
case LBN_SELCHANGE:
SmSelScr(hDlg,(Int)SendDlgItemMessage(hDlg,
LB_SCRIPTS,
LB_GETCURSEL,
0, 0L));
return TRUE;
case LBN_DBLCLK: {
char buffer[_MAX_PATH];
SendDlgItemMessage(hDlg,
LB_SCRIPTS,
LB_GETTEXT,
selScr,
(LPARAM) (LPSTR) buffer);
setLastEdit((String)buffer,0);
runEditor();
return TRUE;
}
}
break;
case IDOK: {
Int i;
for (i=0; i<namesUpto; i++)
if (scriptName[i]) {
free(scriptName[i]);
free(scriptReal[i]);
}
for (i=0; i<smUpto; i++) {
scriptName[i] = smFile[i];
scriptReal[i] = strCopy(RealPath(scriptName[i]));
smFile[i] = 0;
}
namesUpto = smUpto;
numScripts = smLoaded;
dropScriptsFrom(numScripts-1);
PostMessage(hWndMain,WM_COMMAND,ID_COMPILE,0L);
EndDialog(hDlg,TRUE);
return TRUE;
}
case IDCANCEL: {
Int i;
for (i=0; i<smUpto; i++)
if (smFile[i])
free(smFile[i]);
EndDialog(hDlg, TRUE);
return TRUE;
}
}
break;
}
return FALSE;
}
****************************************************************************
****
*** BUG ***: Winhugs crashes when the user loads an script without providing
the full path
Change the function addScript in src\hugs.c to this one
****************************************************************************
****
static Bool local addScript(fname,len) /* read single script file
*/
String fname; /* name of script file
*/
Long len; { /* length of script file
*/
scriptFile = fname;
#if HUGS_FOR_WINDOWS /* Set clock cursor while loading */
allowBreak();
SetCursor(LoadCursor(NULL, IDC_WAIT));
AddFileToFileNamesMenu(&FilesMenu, RealPath(fname));
#endif
Printf("Reading file \"%s\":\n",fname);
setLastEdit(fname,0);
needsImports = FALSE;
parseScript(fname,len); /* process script file
*/
if (needsImports)
return FALSE;
checkDefns();
typeCheckDefns();
compileDefns();
scriptFile = 0;
preludeLoaded = TRUE;
return TRUE;
}
****************************************************************************
****
*** BUG ***: Winhugs crashes when the user loads an script without providing
the full path
Change the function setLastEdit in src\hugs.c to this one
****************************************************************************
****
static Void local setLastEdit(fname,line)/* keep name of last file to edit
*/
String fname;
Int line; {
if (lastEdit)
free(lastEdit);
lastEdit = strCopy(fname);
lastLine = line;
#if HUGS_FOR_WINDOWS
/* Add file to Edit menu */
if (lastEdit)
AddFileToFileNamesMenu(&EditMenu, RealPath(lastEdit));
#endif
}
****************************************************************************
****
*** BUG ***: Winhugs options dialog does not work well
Change the OPTIONSDLGBOX resource in src\winhugs\winhugs.rc to this one
****************************************************************************
****
OPTIONSDLGBOX DIALOG FIXED IMPURE 14, 24, 313, 241
STYLE DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
WS_SYSMENU
CAPTION "Options"
FONT 8, "Ms Sans Serif"
BEGIN
GROUPBOX " Fl&ags: ",-1,5,5,302,110
CONTROL "&s Print no. reductions/cells after
eval",ID_OP,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,12,19,142,10
CONTROL "&t Print type after evaluation",ID_OP+1,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,12,29,142,10
CONTROL "&f Terminate evaluation on first
error",ID_OP+2,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,12,39,142,10
CONTROL "&g Print no. cells recovered after
gc",ID_OP+3,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,12,49,142,10
CONTROL "&G Generate FFI code for foreign
import",ID_OP+4,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,12,59,142,10
CONTROL "&l Literate scripts as default",ID_OP+5,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,12,69,142,10
CONTROL "&e Warn about errors in literate
scripts",ID_OP+6,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,12,79,142,10
CONTROL "&. Print dots to show progress",ID_OP+7,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,12,89,135,10
CONTROL "&q Print nothing to show progress",ID_OP+8,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,12,99,135,10
CONTROL "&Q Qualify names when printing",ID_OP+9,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,160,19,147,10
CONTROL "&w Always show which files loaded",ID_OP+10,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,160,29,147,10
CONTROL "&k Show kind errors in full",ID_OP+11,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,160,39,147,10
CONTROL "&o Allow overlapping instances",ID_OP+12,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,160,49,147,10
CONTROL "&u Use ""show"" to display results",ID_OP+13,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,160,59,147,10
CONTROL "&i Chase imports while loading
files",ID_OP+14,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,160,69,147,10
CONTROL "&A Auto load files",ID_OP+15,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,160,79,147,10
CONTROL "&m Use multi instance resolution ",ID_OP+16,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,160,89,147,10
LTEXT "Path:",-1,12,129,22,8
EDITTEXT ID_PATH,37,127,183,12,ES_AUTOHSCROLL
LTEXT "Preprocessor filter:",-1,12,143,62,8
EDITTEXT ID_PREPROCESSOR,76,141,144,12,ES_AUTOHSCROLL
LTEXT "Editor:",-1,12,157,25,8
EDITTEXT ID_EDITOR,39,155,181,12,ES_AUTOHSCROLL
LTEXT "Prompt string:",-1,12,171,47,8
EDITTEXT ID_PROMPT,62,169,158,12
LTEXT "Repeat last expression string:",-1,12,185,96,8
EDITTEXT ID_LASTEXPR,111,183,109,12
LTEXT "Set constraint cutoff limit:",-1,12,200,89,8
EDITTEXT ID_CUTOFF,97,197,123,12
LTEXT "Heap size:",-1,12,215,47,8
EDITTEXT ID_HEAPSIZE,52,212,168,12
PUSHBUTTON "Ok",IDOK,256,129,40,14
PUSHBUTTON "Cancel",IDCANCEL,256,150,40,14
GROUPBOX "",-1,5,118,227,112
LTEXT "",ID_PLACEBITMAP,246,188,73,1
END
****************************************************************************
****
*** BUG ***: Winhugs could use a different color while printing observations
Change the printObserve function in src\output.c to this one
****************************************************************************
****
Void printObserve(t)
String t; {
Observe i;
String s;
if (! (i=firstObserve())) return;
printingObservations = TRUE;
outputStream = stdout;
#if HUGS_FOR_WINDOWS
{ INT svColor = SetForeColor(MAGENTA);
#endif
putStr("\n>>>>>>> Observations <<<<<<");
newLine(0);
while(i != NIL){
newLine(0);
s = textToStr(observe(i).tag);
if (*t==0 || strcmp(s,t)==0){
putStr(s);
newLine(2);
if (printObsList(observe(i).head,2,FALSE))
newLine(0);
}
i = nextObserve();
}
newLine(0);
printingObservations = FALSE;
#if HUGS_FOR_WINDOWS
SetForeColor(svColor); }
#endif
}
(¯`·.¸¸.-> pepeg <-.¸¸.·´¯)