diff options
Diffstat (limited to 'win32caml')
-rw-r--r-- | win32caml/Makefile | 2 | ||||
-rw-r--r-- | win32caml/editbuffer.c | 767 | ||||
-rw-r--r-- | win32caml/editbuffer.h | 34 | ||||
-rw-r--r-- | win32caml/history.c | 98 | ||||
-rw-r--r-- | win32caml/history.h | 12 | ||||
-rw-r--r-- | win32caml/inria.h | 15 | ||||
-rw-r--r-- | win32caml/libgraph.h | 2 | ||||
-rw-r--r-- | win32caml/menu.c | 161 | ||||
-rw-r--r-- | win32caml/ocaml.c | 2308 | ||||
-rw-r--r-- | win32caml/ocaml.rc | 2 | ||||
-rw-r--r-- | win32caml/startocaml.c | 311 |
11 files changed, 1859 insertions, 1853 deletions
diff --git a/win32caml/Makefile b/win32caml/Makefile index a73b73152..153c9a068 100644 --- a/win32caml/Makefile +++ b/win32caml/Makefile @@ -1,6 +1,6 @@ ######################################################################### # # -# Objective Caml # +# OCaml # # # # Xavier Leroy, projet Cristal, INRIA Rocquencourt # # # diff --git a/win32caml/editbuffer.c b/win32caml/editbuffer.c index 480d22d86..a91e91f9c 100644 --- a/win32caml/editbuffer.c +++ b/win32caml/editbuffer.c @@ -1,8 +1,9 @@ /***********************************************************************/ /* */ -/* Objective Caml */ +/* OCaml */ /* */ /* Developed by Jacob Navia. */ +/* */ /* Copyright 2001 Institut National de Recherche en Informatique et */ /* en Automatique. All rights reserved. This file is distributed */ /* under the terms of the GNU Library General Public License, with */ @@ -22,321 +23,321 @@ /*------------------------------------------------------------------------ Procedure: editbuffer_addline ID:1 - Author: Chris Watford watford@uiuc.edu + Author: Chris Watford watford@uiuc.edu Purpose: Adds a line to the current edit buffer - Input: Line of text to append to the end + Input: Line of text to append to the end Output: Errors: -------------------------------------------------------------------------- Edit History: - 18 Sept 2003 - Chris Watford watford@uiuc.edu - - Corrected doubly linked list issue + 18 Sept 2003 - Chris Watford watford@uiuc.edu + - Corrected doubly linked list issue ------------------------------------------------------------------------*/ BOOL editbuffer_addline(EditBuffer* edBuf, char* line) { - LineList *tail = NULL; //head of the edit buffer line list - LineList *newline = NULL; - - // sanity check - if(edBuf == NULL) - { - return FALSE; - } - - // perform edit buffer sanity checks - if((edBuf->LineCount < 0) || (edBuf->Lines == NULL)) - { - edBuf->LineCount = 0; - } - - // move to the end of the line list in the edit buffer - if((tail = edBuf->Lines) != NULL) - for( ; tail->Next != NULL; tail = tail->Next); - - // create the new line entry - newline = (LineList*)SafeMalloc(sizeof(LineList)); - newline->Next = NULL; - newline->Prev = tail; - newline->Text = (char*)SafeMalloc(strlen(line)+1); - strncpy(newline->Text, line, strlen(line)+1); - newline->Text[strlen(line)] = '\0'; - - // add it to the list as the head or the tail - if(tail != NULL) - { - tail->Next = newline; - } else { - edBuf->Lines = newline; - } - - // update the number of lines in the buffer - edBuf->LineCount++; - - return TRUE; + LineList *tail = NULL; //head of the edit buffer line list + LineList *newline = NULL; + + // sanity check + if(edBuf == NULL) + { + return FALSE; + } + + // perform edit buffer sanity checks + if((edBuf->LineCount < 0) || (edBuf->Lines == NULL)) + { + edBuf->LineCount = 0; + } + + // move to the end of the line list in the edit buffer + if((tail = edBuf->Lines) != NULL) + for( ; tail->Next != NULL; tail = tail->Next); + + // create the new line entry + newline = (LineList*)SafeMalloc(sizeof(LineList)); + newline->Next = NULL; + newline->Prev = tail; + newline->Text = (char*)SafeMalloc(strlen(line)+1); + strncpy(newline->Text, line, strlen(line)+1); + newline->Text[strlen(line)] = '\0'; + + // add it to the list as the head or the tail + if(tail != NULL) + { + tail->Next = newline; + } else { + edBuf->Lines = newline; + } + + // update the number of lines in the buffer + edBuf->LineCount++; + + return TRUE; } /*------------------------------------------------------------------------ Procedure: editbuffer_updateline ID:1 - Author: Chris Watford watford@uiuc.edu + Author: Chris Watford watford@uiuc.edu Purpose: Updates the edit buffer's internal contents for a line - Input: idx - Line index - line - String to add - Output: if the line was updated or not + Input: idx - Line index + line - String to add + Output: if the line was updated or not Errors: ------------------------------------------------------------------------*/ BOOL editbuffer_updateline(EditBuffer* edBuf, int idx, char* line) { - LineList *update = edBuf->Lines; //head of the edit buffer line list - LineList *newline = NULL; - int i; - - // sanity checks - if(edBuf == NULL) - { - return FALSE; - } else if( (edBuf->LineCount == 0) || - (edBuf->Lines == NULL) || - (idx >= edBuf->LineCount) || - (idx < 0) ) { - return FALSE; - } - - // move to the index in the line list - // i left in update != NULL as a sanity check - for(i = 0; ((update != NULL) && (i != idx)); update = update->Next, i++); - - // did things mess up? - if( (update == NULL) || (i != idx) ) - { - return FALSE; - } - - // get rid of the old line - free(update->Text); - - // get the new line updated - update->Text = (char*)SafeMalloc(strlen(line)+1); - strncpy(update->Text, line, strlen(line)+1); - update->Text[strlen(line)] = '\0'; - - return TRUE; + LineList *update = edBuf->Lines; //head of the edit buffer line list + LineList *newline = NULL; + int i; + + // sanity checks + if(edBuf == NULL) + { + return FALSE; + } else if( (edBuf->LineCount == 0) || + (edBuf->Lines == NULL) || + (idx >= edBuf->LineCount) || + (idx < 0) ) { + return FALSE; + } + + // move to the index in the line list + // i left in update != NULL as a sanity check + for(i = 0; ((update != NULL) && (i != idx)); update = update->Next, i++); + + // did things mess up? + if( (update == NULL) || (i != idx) ) + { + return FALSE; + } + + // get rid of the old line + free(update->Text); + + // get the new line updated + update->Text = (char*)SafeMalloc(strlen(line)+1); + strncpy(update->Text, line, strlen(line)+1); + update->Text[strlen(line)] = '\0'; + + return TRUE; } /*------------------------------------------------------------------------ Procedure: editbuffer_updateoraddline ID:1 - Author: Chris Watford watford@uiuc.edu + Author: Chris Watford watford@uiuc.edu Purpose: Updates the edit buffer's internal contents for a line - Input: idx - Line index - line - String to add - Output: if the line was updated or not + Input: idx - Line index + line - String to add + Output: if the line was updated or not Errors: ------------------------------------------------------------------------*/ BOOL editbuffer_updateoraddline(EditBuffer* edBuf, int idx, char* line) { - LineList *update; - - // sanity checks - if(edBuf == NULL) - { - return FALSE; - } else if((idx > edBuf->LineCount) || (idx < 0)) { - return FALSE; - } - - update = edBuf->Lines; //head of the edit buffer line list - - // do we update or add? - if((idx < edBuf->LineCount) && (edBuf->Lines != NULL)) - { //interior line, update - return editbuffer_updateline(edBuf, idx, line); - } else { - //fence line, add - return editbuffer_addline(edBuf, line); - } + LineList *update; + + // sanity checks + if(edBuf == NULL) + { + return FALSE; + } else if((idx > edBuf->LineCount) || (idx < 0)) { + return FALSE; + } + + update = edBuf->Lines; //head of the edit buffer line list + + // do we update or add? + if((idx < edBuf->LineCount) && (edBuf->Lines != NULL)) + { //interior line, update + return editbuffer_updateline(edBuf, idx, line); + } else { + //fence line, add + return editbuffer_addline(edBuf, line); + } } /*------------------------------------------------------------------------ Procedure: editbuffer_removeline ID:1 - Author: Chris Watford watford@uiuc.edu + Author: Chris Watford watford@uiuc.edu Purpose: Removes a line from the edit buffer - Input: idx - Line index to remove - Output: if the line was removed or not + Input: idx - Line index to remove + Output: if the line was removed or not Errors: -------------------------------------------------------------------------- Edit History: - 18 Sept 2003 - Chris Watford watford@uiuc.edu - - Added to allow backspace and delete support - - Corrected doubly linked list issue + 18 Sept 2003 - Chris Watford watford@uiuc.edu + - Added to allow backspace and delete support + - Corrected doubly linked list issue ------------------------------------------------------------------------*/ BOOL editbuffer_removeline(EditBuffer* edBuf, int idx) { - LineList *update = NULL; - int i = 0; - - // sanity checks - if(edBuf == NULL) - { - return FALSE; - } else if( (edBuf->LineCount == 0) || - (edBuf->Lines == NULL) || - (idx >= edBuf->LineCount) || - (idx < 0) ) { - return FALSE; - } - - // move to the index in the line list - // i left in update != NULL as a sanity check - for(i = 0, update = edBuf->Lines; ((update != NULL) && (i != idx)); update = update->Next, i++); - - // remove this line - if(update != NULL) - { - // break links, removing our line - if(update->Prev != NULL) - { - // we're not the first so just break the link - update->Prev->Next = update->Next; - - // fix the prev check - if(update->Next != NULL) - update->Next->Prev = update->Prev; - } else { - // we're the first, attach the next guy to lines - edBuf->Lines = update->Next; - } - - // one less line to worry about - edBuf->LineCount--; - - // get rid of the text - if(update->Text != NULL) - free(update->Text); - - // get rid of us - free(update); - - return TRUE; - } - - return FALSE; + LineList *update = NULL; + int i = 0; + + // sanity checks + if(edBuf == NULL) + { + return FALSE; + } else if( (edBuf->LineCount == 0) || + (edBuf->Lines == NULL) || + (idx >= edBuf->LineCount) || + (idx < 0) ) { + return FALSE; + } + + // move to the index in the line list + // i left in update != NULL as a sanity check + for(i = 0, update = edBuf->Lines; ((update != NULL) && (i != idx)); update = update->Next, i++); + + // remove this line + if(update != NULL) + { + // break links, removing our line + if(update->Prev != NULL) + { + // we're not the first so just break the link + update->Prev->Next = update->Next; + + // fix the prev check + if(update->Next != NULL) + update->Next->Prev = update->Prev; + } else { + // we're the first, attach the next guy to lines + edBuf->Lines = update->Next; + } + + // one less line to worry about + edBuf->LineCount--; + + // get rid of the text + if(update->Text != NULL) + free(update->Text); + + // get rid of us + free(update); + + return TRUE; + } + + return FALSE; } /*------------------------------------------------------------------------ Procedure: editbuffer_getasline ID:1 - Author: Chris Watford watford@uiuc.edu + Author: Chris Watford watford@uiuc.edu Purpose: Returns the edit buffer as one big line, \n's and \t's - become spaces. + become spaces. Input: Output: Errors: ------------------------------------------------------------------------*/ char* editbuffer_getasline(EditBuffer* edBuf) { - LineList *line = NULL; //head of the edit buffer line list - char* retline = (char*)realloc(NULL, 1); - unsigned int i = 0; - - // fix retline bug - retline[0] = '\0'; - - // sanity checks - if(edBuf == NULL) - { - return NULL; - } else if (edBuf->LineCount == 0 || edBuf->Lines == NULL) { - // fix any possible errors that may come from this - edBuf->LineCount = 0; - edBuf->Lines = NULL; - return NULL; - } - - // get the big line - for(line = edBuf->Lines; line != NULL; line = line->Next) - { - if(line->Text != NULL) - { - retline = (char*)realloc(retline, (strlen(retline) + strlen(line->Text) + (strlen(retline) > 0 ? 2 : 1))); - - if(strlen(retline) > 0) - retline = strcat(retline, " "); - - retline = strcat(retline, line->Text); - - //concat in the hoouuusssseee! - } - } - - // now we have the big line, so lets ditch all \n's \t's and \r's - for(i = 0; i < strlen(retline); i++) - { - switch(retline[i]) - { - case '\n': - case '\t': - case '\r': - retline[i] = ' '; - } - } - - return retline; + LineList *line = NULL; //head of the edit buffer line list + char* retline = (char*)realloc(NULL, 1); + unsigned int i = 0; + + // fix retline bug + retline[0] = '\0'; + + // sanity checks + if(edBuf == NULL) + { + return NULL; + } else if (edBuf->LineCount == 0 || edBuf->Lines == NULL) { + // fix any possible errors that may come from this + edBuf->LineCount = 0; + edBuf->Lines = NULL; + return NULL; + } + + // get the big line + for(line = edBuf->Lines; line != NULL; line = line->Next) + { + if(line->Text != NULL) + { + retline = (char*)realloc(retline, (strlen(retline) + strlen(line->Text) + (strlen(retline) > 0 ? 2 : 1))); + + if(strlen(retline) > 0) + retline = strcat(retline, " "); + + retline = strcat(retline, line->Text); + + //concat in the hoouuusssseee! + } + } + + // now we have the big line, so lets ditch all \n's \t's and \r's + for(i = 0; i < strlen(retline); i++) + { + switch(retline[i]) + { + case '\n': + case '\t': + case '\r': + retline[i] = ' '; + } + } + + return retline; } /*------------------------------------------------------------------------ Procedure: editbuffer_getasbuffer ID:1 - Author: Chris Watford watford@uiuc.edu + Author: Chris Watford watford@uiuc.edu Purpose: Returns the edit buffer as one big line, \n's and \t's - become spaces. + become spaces. Input: Output: Errors: ------------------------------------------------------------------------*/ char* editbuffer_getasbuffer(EditBuffer* edBuf) { - LineList *line = NULL; //head of the edit buffer line list - char* retbuf = (char*)realloc(NULL, 1); - unsigned int i = 0; - - // fix retline bug - retbuf[0] = '\0'; - - // sanity checks - if(edBuf == NULL) - { - return NULL; - } else if (edBuf->LineCount == 0 || edBuf->Lines == NULL) { - // fix any possible errors that may come from this - edBuf->LineCount = 0; - edBuf->Lines = NULL; - return NULL; - } - - // get the big line - for(line = edBuf->Lines; line != NULL; line = line->Next) - { - if(line->Text != NULL) - { - int len = strlen(retbuf); - len += strlen(line->Text) + (len > 0 ? 3 : 1); - - retbuf = (char*)realloc(retbuf, len); - - if(strlen(retbuf) > 0) - retbuf = strcat(retbuf, "\r\n"); - - retbuf = strcat(retbuf, line->Text); - - retbuf[len-1] = '\0'; - - //concat in the hoouuusssseee! - } - } - - return retbuf; + LineList *line = NULL; //head of the edit buffer line list + char* retbuf = (char*)realloc(NULL, 1); + unsigned int i = 0; + + // fix retline bug + retbuf[0] = '\0'; + + // sanity checks + if(edBuf == NULL) + { + return NULL; + } else if (edBuf->LineCount == 0 || edBuf->Lines == NULL) { + // fix any possible errors that may come from this + edBuf->LineCount = 0; + edBuf->Lines = NULL; + return NULL; + } + + // get the big line + for(line = edBuf->Lines; line != NULL; line = line->Next) + { + if(line->Text != NULL) + { + int len = strlen(retbuf); + len += strlen(line->Text) + (len > 0 ? 3 : 1); + + retbuf = (char*)realloc(retbuf, len); + + if(strlen(retbuf) > 0) + retbuf = strcat(retbuf, "\r\n"); + + retbuf = strcat(retbuf, line->Text); + + retbuf[len-1] = '\0'; + + //concat in the hoouuusssseee! + } + } + + return retbuf; } /*------------------------------------------------------------------------ Procedure: editbuffer_lastline ID:1 - Author: Chris Watford watford@uiuc.edu + Author: Chris Watford watford@uiuc.edu Purpose: Returns the last line in the edit buffer Input: Output: @@ -344,111 +345,111 @@ char* editbuffer_getasbuffer(EditBuffer* edBuf) ------------------------------------------------------------------------*/ char* editbuffer_lastline(EditBuffer* edBuf) { - LineList *line = NULL; //head of the edit buffer line list - - // sanity checks - if(edBuf == NULL) - { - return NULL; - } else if (edBuf->LineCount == 0 || edBuf->Lines == NULL) { - // fix any possible errors that may come from this - edBuf->LineCount = 0; - edBuf->Lines = NULL; - return NULL; - } - - // go to the last line - for(line = edBuf->Lines; line->Next != NULL; line = line->Next); - - return line->Text; + LineList *line = NULL; //head of the edit buffer line list + + // sanity checks + if(edBuf == NULL) + { + return NULL; + } else if (edBuf->LineCount == 0 || edBuf->Lines == NULL) { + // fix any possible errors that may come from this + edBuf->LineCount = 0; + edBuf->Lines = NULL; + return NULL; + } + + // go to the last line + for(line = edBuf->Lines; line->Next != NULL; line = line->Next); + + return line->Text; } /*------------------------------------------------------------------------ Procedure: editbuffer_copy ID:1 - Author: Chris Watford watford@uiuc.edu + Author: Chris Watford watford@uiuc.edu Purpose: Makes an exact copy of an edit buffer Input: Output: Errors: -------------------------------------------------------------------------- Edit History: - 16 Sept 2003 - Chris Watford watford@uiuc.edu - - Added to make copies of history entries - 18 Sept 2003 - Chris Watford watford@uiuc.edu - - Corrected doubly linked list issue - 06 Oct 2003 - Chris Watford watford@uiuc.edu - - Added isCorrect flag + 16 Sept 2003 - Chris Watford watford@uiuc.edu + - Added to make copies of history entries + 18 Sept 2003 - Chris Watford watford@uiuc.edu + - Corrected doubly linked list issue + 06 Oct 2003 - Chris Watford watford@uiuc.edu + - Added isCorrect flag ------------------------------------------------------------------------*/ EditBuffer* editbuffer_copy(EditBuffer* edBuf) { - // sanity checks - if(edBuf == NULL) - { - return NULL; - } else { - EditBuffer* copy = (EditBuffer*)SafeMalloc(sizeof(EditBuffer)); - LineList* lines = edBuf->Lines; - LineList* lastLine = NULL; - - // clear its initial values - copy->LineCount = 0; - copy->Lines = NULL; - copy->isCorrect = FALSE; - - // well we don't have to copy much - if((lines == NULL) || (edBuf->LineCount <= 0)) - { - return copy; - } - - // get if its correct - copy->isCorrect = edBuf->isCorrect; - - // go through each line, malloc it and add it - for( ; lines != NULL; lines = lines->Next) - { - LineList* curline = (LineList*)SafeMalloc(sizeof(LineList)); - curline->Next = NULL; - curline->Prev = NULL; - - // if there was a last line, link them to us - if(lastLine != NULL) - { - lastLine->Next = curline; - curline->Prev = lastLine; - } - - // are we the first line? add us to the edit buffer as the first - if(copy->Lines == NULL) - { - copy->Lines = curline; - } - - // check if there is text on the line - if(lines->Text == NULL) - { // no text, make it blankz0r - curline->Text = (char*)SafeMalloc(sizeof(char)); - curline->Text[0] = '\0'; - } else { - // there is text, copy it and null-terminate - curline->Text = (char*)SafeMalloc(strlen(lines->Text) + 1); - strncpy(curline->Text, lines->Text, strlen(lines->Text)); - curline->Text[strlen(lines->Text)] = '\0'; - } - - // up the line count and make us the last line - copy->LineCount++; - lastLine = curline; - } - - // return our new copy - return copy; - } + // sanity checks + if(edBuf == NULL) + { + return NULL; + } else { + EditBuffer* copy = (EditBuffer*)SafeMalloc(sizeof(EditBuffer)); + LineList* lines = edBuf->Lines; + LineList* lastLine = NULL; + + // clear its initial values + copy->LineCount = 0; + copy->Lines = NULL; + copy->isCorrect = FALSE; + + // well we don't have to copy much + if((lines == NULL) || (edBuf->LineCount <= 0)) + { + return copy; + } + + // get if its correct + copy->isCorrect = edBuf->isCorrect; + + // go through each line, malloc it and add it + for( ; lines != NULL; lines = lines->Next) + { + LineList* curline = (LineList*)SafeMalloc(sizeof(LineList)); + curline->Next = NULL; + curline->Prev = NULL; + + // if there was a last line, link them to us + if(lastLine != NULL) + { + lastLine->Next = curline; + curline->Prev = lastLine; + } + + // are we the first line? add us to the edit buffer as the first + if(copy->Lines == NULL) + { + copy->Lines = curline; + } + + // check if there is text on the line + if(lines->Text == NULL) + { // no text, make it blankz0r + curline->Text = (char*)SafeMalloc(sizeof(char)); + curline->Text[0] = '\0'; + } else { + // there is text, copy it and null-terminate + curline->Text = (char*)SafeMalloc(strlen(lines->Text) + 1); + strncpy(curline->Text, lines->Text, strlen(lines->Text)); + curline->Text[strlen(lines->Text)] = '\0'; + } + + // up the line count and make us the last line + copy->LineCount++; + lastLine = curline; + } + + // return our new copy + return copy; + } } /*------------------------------------------------------------------------ Procedure: editbuffer_destroy ID:1 - Author: Chris Watford watford@uiuc.edu + Author: Chris Watford watford@uiuc.edu Purpose: Destroys an edit buffer Input: Output: @@ -456,59 +457,59 @@ EditBuffer* editbuffer_copy(EditBuffer* edBuf) ------------------------------------------------------------------------*/ void editbuffer_destroy(EditBuffer* edBuf) { - // sanity checks - if(edBuf == NULL) - { // nothing to do - return; - } else if(edBuf->Lines != NULL) { - LineList* lastline = NULL; - - // loop through each line free'ing its text - for( ; edBuf->Lines != NULL; edBuf->Lines = edBuf->Lines->Next) - { - if(edBuf->Lines->Text != NULL) - free(edBuf->Lines->Text); - - // if there was a line before us, free it - if(lastline != NULL) - { - free(lastline); - lastline = NULL; - } - - lastline = edBuf->Lines; - } - - // free the last line - free(lastline); - } - - // free ourself - free(edBuf); + // sanity checks + if(edBuf == NULL) + { // nothing to do + return; + } else if(edBuf->Lines != NULL) { + LineList* lastline = NULL; + + // loop through each line free'ing its text + for( ; edBuf->Lines != NULL; edBuf->Lines = edBuf->Lines->Next) + { + if(edBuf->Lines->Text != NULL) + free(edBuf->Lines->Text); + + // if there was a line before us, free it + if(lastline != NULL) + { + free(lastline); + lastline = NULL; + } + + lastline = edBuf->Lines; + } + + // free the last line + free(lastline); + } + + // free ourself + free(edBuf); } /*------------------------------------------------------------------------ Procedure: editbuffer_new ID:1 - Author: Chris Watford watford@uiuc.edu + Author: Chris Watford watford@uiuc.edu Purpose: Creates an edit buffer Input: Output: Errors: -------------------------------------------------------------------------- Edit History: - 06 Oct 2003 - Chris Watford watford@uiuc.edu - - Added isCorrect flag + 06 Oct 2003 - Chris Watford watford@uiuc.edu + - Added isCorrect flag ------------------------------------------------------------------------*/ EditBuffer* editbuffer_new(void) { - // create a new one - EditBuffer *edBuf = (EditBuffer*)SafeMalloc(sizeof(EditBuffer)); - - // default vals - edBuf->LineCount = 0; - edBuf->Lines = NULL; - edBuf->isCorrect = FALSE; - - // return it - return edBuf; + // create a new one + EditBuffer *edBuf = (EditBuffer*)SafeMalloc(sizeof(EditBuffer)); + + // default vals + edBuf->LineCount = 0; + edBuf->Lines = NULL; + edBuf->isCorrect = FALSE; + + // return it + return edBuf; } diff --git a/win32caml/editbuffer.h b/win32caml/editbuffer.h index 91e2999c3..add99b2ee 100644 --- a/win32caml/editbuffer.h +++ b/win32caml/editbuffer.h @@ -1,6 +1,6 @@ /***********************************************************************/ /* */ -/* Objective Caml */ +/* OCaml */ /* */ /* Jacob Navia, after Xavier Leroy */ /* */ @@ -22,26 +22,26 @@ // All the below was added by Chris Watford watford@uiuc.edu typedef struct tagLineList { - struct tagLineList *Next; - struct tagLineList *Prev; - char *Text; + struct tagLineList *Next; + struct tagLineList *Prev; + char *Text; } LineList; typedef struct tagEditBuffer { - int LineCount; - struct tagLineList *Lines; - BOOL isCorrect; + int LineCount; + struct tagLineList *Lines; + BOOL isCorrect; } EditBuffer; -BOOL editbuffer_addline (EditBuffer* edBuf, char* line); -BOOL editbuffer_updateline (EditBuffer* edBuf, int idx, char* line); -BOOL editbuffer_updateoraddline (EditBuffer* edBuf, int idx, char* line); -BOOL editbuffer_removeline (EditBuffer* edBuf, int idx); -char* editbuffer_getasline (EditBuffer* edBuf); -char* editbuffer_getasbuffer (EditBuffer* edBuf); -char* editbuffer_lastline (EditBuffer* edBuf); -EditBuffer* editbuffer_copy (EditBuffer* edBuf); -void editbuffer_destroy (EditBuffer* edBuf); -EditBuffer* editbuffer_new (void); +BOOL editbuffer_addline (EditBuffer* edBuf, char* line); +BOOL editbuffer_updateline (EditBuffer* edBuf, int idx, char* line); +BOOL editbuffer_updateoraddline (EditBuffer* edBuf, int idx, char* line); +BOOL editbuffer_removeline (EditBuffer* edBuf, int idx); +char* editbuffer_getasline (EditBuffer* edBuf); +char* editbuffer_getasbuffer (EditBuffer* edBuf); +char* editbuffer_lastline (EditBuffer* edBuf); +EditBuffer* editbuffer_copy (EditBuffer* edBuf); +void editbuffer_destroy (EditBuffer* edBuf); +EditBuffer* editbuffer_new (void); #endif diff --git a/win32caml/history.c b/win32caml/history.c index 11397ac66..9a0003482 100644 --- a/win32caml/history.c +++ b/win32caml/history.c @@ -1,6 +1,6 @@ /***********************************************************************/ /* */ -/* Objective Caml */ +/* OCaml */ /* */ /* Jacob Navia, after Xavier Leroy */ /* */ @@ -21,78 +21,78 @@ /*------------------------------------------------------------------------ Procedure: AddToHistory ID:2 -Author: Chris Watford watford@uiuc.edu +Author: Chris Watford watford@uiuc.edu Purpose: Adds an edit buffer to the history control -Input: Pointer to the edit buffer to add +Input: Pointer to the edit buffer to add Output: Errors: -------------------------------------------------------------------------- Edit History: - 15 Sept 2003 - Chris Watford watford@uiuc.edu - - Complete rewrite - - Got it to add the edit buffer to the history - 17 Sept 2003 - Chris Watford watford@uiuc.edu - - Added doubly link list support + 15 Sept 2003 - Chris Watford watford@uiuc.edu + - Complete rewrite + - Got it to add the edit buffer to the history + 17 Sept 2003 - Chris Watford watford@uiuc.edu + - Added doubly link list support ------------------------------------------------------------------------*/ void AddToHistory(EditBuffer *edBuf) { - StatementHistory *newLine; + StatementHistory *newLine; - // sanity checks - if(edBuf == NULL) - { - return; - } else if (edBuf->LineCount == 0 || edBuf->Lines == NULL) { - // fix any possible errors that may come from this - edBuf->LineCount = 0; - edBuf->Lines = NULL; - return; - } + // sanity checks + if(edBuf == NULL) + { + return; + } else if (edBuf->LineCount == 0 || edBuf->Lines == NULL) { + // fix any possible errors that may come from this + edBuf->LineCount = 0; + edBuf->Lines = NULL; + return; + } - // setup newline and add as the front of the linked list - newLine = SafeMalloc(sizeof(StatementHistory)); - newLine->Next = History; - newLine->Prev = NULL; - newLine->Statement = edBuf; + // setup newline and add as the front of the linked list + newLine = SafeMalloc(sizeof(StatementHistory)); + newLine->Next = History; + newLine->Prev = NULL; + newLine->Statement = edBuf; - // setup back linking - if(History != NULL) - History->Prev = newLine; + // setup back linking + if(History != NULL) + History->Prev = newLine; - // set the history up - History = newLine; + // set the history up + History = newLine; - // search for the new history tail - for(HistoryTail = (HistoryTail != NULL ? HistoryTail : History); HistoryTail->Next != NULL; HistoryTail = HistoryTail->Next); + // search for the new history tail + for(HistoryTail = (HistoryTail != NULL ? HistoryTail : History); HistoryTail->Next != NULL; HistoryTail = HistoryTail->Next); } /*------------------------------------------------------------------------ Procedure: GetHistoryLine ID:2 -Author: Chris Watford watford@uiuc.edu +Author: Chris Watford watford@uiuc.edu Purpose: Returns an entry from the history table -Input: Index of the history entry to return -Output: The history entry as a single line +Input: Index of the history entry to return +Output: The history entry as a single line Errors: -------------------------------------------------------------------------- Edit History: - 15 Sept 2003 - Chris Watford watford@uiuc.edu - - Complete rewrite - 17 Sept 2003 - Chris Watford watford@uiuc.edu - - Added doubly link list support + 15 Sept 2003 - Chris Watford watford@uiuc.edu + - Complete rewrite + 17 Sept 2003 - Chris Watford watford@uiuc.edu + - Added doubly link list support ------------------------------------------------------------------------*/ char *GetHistoryLine(int n) { - StatementHistory *histentry = History; - int i; + StatementHistory *histentry = History; + int i; - // traverse linked list looking for member n - for (i = 0; ((i < n) && (histentry != NULL)); i++, histentry = histentry->Next); + // traverse linked list looking for member n + for (i = 0; ((i < n) && (histentry != NULL)); i++, histentry = histentry->Next); - // figure out what to return - if (histentry != NULL) - { - return editbuffer_getasline(histentry->Statement); - } else { - return ""; - } + // figure out what to return + if (histentry != NULL) + { + return editbuffer_getasline(histentry->Statement); + } else { + return ""; + } } diff --git a/win32caml/history.h b/win32caml/history.h index a9ba85841..4fceef1fe 100644 --- a/win32caml/history.h +++ b/win32caml/history.h @@ -1,6 +1,6 @@ /***********************************************************************/ /* */ -/* Objective Caml */ +/* OCaml */ /* */ /* Jacob Navia, after Xavier Leroy */ /* */ @@ -23,13 +23,13 @@ // Simple linked list for holding the history lines typedef struct tagStatementHistory { - struct tagStatementHistory *Next; - struct tagStatementHistory *Prev; - EditBuffer *Statement; + struct tagStatementHistory *Next; + struct tagStatementHistory *Prev; + EditBuffer *Statement; } StatementHistory; -void AddToHistory (EditBuffer *edBuf); -char *GetHistoryLine (int n); +void AddToHistory (EditBuffer *edBuf); +char *GetHistoryLine (int n); static BOOL CALLBACK HistoryDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); #endif diff --git a/win32caml/inria.h b/win32caml/inria.h index 095cbcc75..325fb38ac 100644 --- a/win32caml/inria.h +++ b/win32caml/inria.h @@ -1,8 +1,9 @@ /***********************************************************************/ /* */ -/* Objective Caml */ +/* OCaml */ /* */ /* Developed by Jacob Navia. */ +/* */ /* Copyright 2001 Institut National de Recherche en Informatique et */ /* en Automatique. All rights reserved. This file is distributed */ /* under the terms of the GNU Library General Public License, with */ @@ -112,12 +113,12 @@ void RewriteCurrentEditBuffer(void); void RefreshCurrentEditBuffer(void); // **************** User defined window messages ************* -#define WM_NEWLINE (WM_USER+6000) -#define WM_TIMERTICK (WM_USER+6001) -#define WM_QUITOCAML (WM_USER+6002) -#define WM_SYNTAXERROR (WM_USER+6003) -#define WM_UNBOUNDVAL (WM_USER+6004) -#define WM_ILLEGALCHAR (WM_USER+6005) +#define WM_NEWLINE (WM_USER+6000) +#define WM_TIMERTICK (WM_USER+6001) +#define WM_QUITOCAML (WM_USER+6002) +#define WM_SYNTAXERROR (WM_USER+6003) +#define WM_UNBOUNDVAL (WM_USER+6004) +#define WM_ILLEGALCHAR (WM_USER+6005) // ********************** Structures *********************** typedef struct tagPosition { diff --git a/win32caml/libgraph.h b/win32caml/libgraph.h index 3bfaff301..1df232988 100644 --- a/win32caml/libgraph.h +++ b/win32caml/libgraph.h @@ -1,6 +1,6 @@ /***********************************************************************/ /* */ -/* Objective Caml */ +/* OCaml */ /* */ /* Jacob Navia, after Xavier Leroy */ /* */ diff --git a/win32caml/menu.c b/win32caml/menu.c index 9ab0f5f37..f0dcb5bbe 100644 --- a/win32caml/menu.c +++ b/win32caml/menu.c @@ -1,8 +1,9 @@ /***********************************************************************/ /* */ -/* Objective Caml */ +/* OCaml */ /* */ /* Developed by Jacob Navia. */ +/* */ /* Copyright 2001 Institut National de Recherche en Informatique et */ /* en Automatique. All rights reserved. This file is distributed */ /* under the terms of the GNU Library General Public License, with */ @@ -396,25 +397,25 @@ void AddLineToControl(char *buf) /*------------------------------------------------------------------------ Procedure: AddStringToControl ID:1 - Author: Chris Watford watford@uiuc.edu + Author: Chris Watford watford@uiuc.edu Purpose: It will ad the given text at the end of the edit control. This simulates user input. The history will not - be modified by this procedure. + be modified by this procedure. Input: The text to be added Output: None Errors: If the line is empty, nothing will be done -------------------------------------------------------------------------- Edit History: - 16 Sept 2003 - Chris Watford watford@uiuc.edu - - Basically this is AddLineToControl, but without appending a - newline + 16 Sept 2003 - Chris Watford watford@uiuc.edu + - Basically this is AddLineToControl, but without appending a + newline ------------------------------------------------------------------------*/ void AddStringToControl(char* buf) { HWND hEditCtrl; - if(buf == NULL) - return; + if(buf == NULL) + return; if((*buf) == 0) return; @@ -451,10 +452,10 @@ static BOOL CALLBACK AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM Errors: -------------------------------------------------------------------------- Edit History: - 15 Sept 2003 - Chris Watford watford@uiuc.edu - - Added support for my StatementHistory structure - - Added the ability to export it as its exact entry, rather than - just a 1 liner + 15 Sept 2003 - Chris Watford watford@uiuc.edu + - Added support for my StatementHistory structure + - Added the ability to export it as its exact entry, rather than + just a 1 liner ------------------------------------------------------------------------*/ static BOOL CALLBACK HistoryDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { @@ -468,7 +469,7 @@ static BOOL CALLBACK HistoryDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPAR histentry = History; // get our statement history object idx = 0; - // loop through each history entry adding it to the dialog + // loop through each history entry adding it to the dialog while (histentry != NULL) { SendDlgItemMessage(hDlg,IDLIST,LB_INSERTSTRING,0,(LPARAM)editbuffer_getasline(histentry->Statement)); SendDlgItemMessage(hDlg,IDLIST,LB_SETITEMDATA,0,(LPARAM)idx); @@ -515,8 +516,8 @@ static BOOL CALLBACK HistoryDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPAR error box -------------------------------------------------------------------------- Edit History: - 06 Oct 2003 - Chris Watford watford@uiuc.edu - - Corrected wsprintf error + 06 Oct 2003 - Chris Watford watford@uiuc.edu + - Corrected wsprintf error ------------------------------------------------------------------------*/ static void SaveText(char *fname) { @@ -528,8 +529,8 @@ static void SaveText(char *fname) f = fopen(fname,"wb"); if (f == NULL) - { - // corrected error using wsprintf + { + // corrected error using wsprintf wsprintf(buf, "Impossible to open %s for writing", fname); ShowDbgMsg(buf); @@ -537,11 +538,11 @@ static void SaveText(char *fname) } for (i = 0; i < linesCount; i++) - { + { *(unsigned short *)buf = 8100; len = SendMessage(hEdit, EM_GETLINE, i, (LPARAM)buf); buf[len] = '\0'; - fprintf(f, "%s\r\n", buf+1); + fprintf(f, "%s\r\n", buf+1); //fwrite(buf,1,len+2,f); } @@ -551,9 +552,9 @@ static void SaveText(char *fname) /*------------------------------------------------------------------------ Procedure: SaveML ID:1 - Author: Chris Watford watford@uiuc.edu + Author: Chris Watford watford@uiuc.edu Purpose: Saves the ML source to a file, commenting out functions - that contained errors + that contained errors Input: The name of the file where the session will be saved Output: The session is saved Errors: If it can't open the file for writing it will show an @@ -567,47 +568,47 @@ static void SaveML(char *fname) f = fopen(fname, "wb"); if(f == NULL) - { + { wsprintf(buf, "Impossible to open %s for writing", fname); ShowDbgMsg(buf); return; } - fprintf(f, "(* %s *)\r\n\r\n", fname); - - if(History != NULL) - { - StatementHistory *h = NULL; - EditBuffer *stmt = NULL; - - // get to the end - for(h = History; h->Next != NULL; h = h->Next); - - // go back :( - // this is NOT the fastest method, BUT this is the easiest - // on the subsystem - for(; h != NULL; h = h->Prev) - { - stmt = h->Statement; - - if(stmt != NULL) - { - // comment out incorrect lines - if(stmt->isCorrect) - { - char *buff = editbuffer_getasbuffer(stmt); - fprintf(f, "%s\r\n", buff); - free(buff); - } else { - char *buff = editbuffer_getasbuffer(stmt); - fprintf(f, "(* Syntax Error or Unbound Value\r\n%s\r\n *)\r\n", buff); - free(buff); - } - } - - fprintf(f, "\r\n"); - } - } + fprintf(f, "(* %s *)\r\n\r\n", fname); + + if(History != NULL) + { + StatementHistory *h = NULL; + EditBuffer *stmt = NULL; + + // get to the end + for(h = History; h->Next != NULL; h = h->Next); + + // go back :( + // this is NOT the fastest method, BUT this is the easiest + // on the subsystem + for(; h != NULL; h = h->Prev) + { + stmt = h->Statement; + + if(stmt != NULL) + { + // comment out incorrect lines + if(stmt->isCorrect) + { + char *buff = editbuffer_getasbuffer(stmt); + fprintf(f, "%s\r\n", buff); + free(buff); + } else { + char *buff = editbuffer_getasbuffer(stmt); + fprintf(f, "(* Syntax Error or Unbound Value\r\n%s\r\n *)\r\n", buff); + free(buff); + } + } + + fprintf(f, "\r\n"); + } + } fclose(f); free(buf); @@ -615,15 +616,15 @@ static void SaveML(char *fname) /*------------------------------------------------------------------------ Procedure: Add_Clipboard_To_Queue ID:1 - Author: Chris Watford watford@uiuc.edu + Author: Chris Watford watford@uiuc.edu Purpose: Adds the clipboard text to the control Input: Output: Errors: -------------------------------------------------------------------------- Edit History: - 16 Sept 2003 - Chris Watford watford@uiuc.edu - - Added method to update edit buffer with paste contents + 16 Sept 2003 - Chris Watford watford@uiuc.edu + - Added method to update edit buffer with paste contents ------------------------------------------------------------------------*/ static void Add_Clipboard_To_Queue(void) { @@ -636,7 +637,7 @@ static void Add_Clipboard_To_Queue(void) char *str = GlobalLock(hClipData); if (str != NULL) - { + { while ((*str) != 0) { if (*str != '\r') @@ -645,9 +646,9 @@ static void Add_Clipboard_To_Queue(void) str++; } - // added to fix odd errors - RefreshCurrentEditBuffer(); - } + // added to fix odd errors + RefreshCurrentEditBuffer(); + } GlobalUnlock(hClipData); } @@ -659,7 +660,7 @@ static void Add_Clipboard_To_Queue(void) /*------------------------------------------------------------------------ Procedure: CopyToClipboard ID:1 Purpose: Copies text to the clipboard - Input: Window with the edit control + Input: Window with the edit control Output: Errors: ------------------------------------------------------------------------*/ @@ -673,7 +674,7 @@ static void CopyToClipboard(HWND hwnd) Procedure: ResetText ID:1 Purpose: Resets the text? I'm not really sure Input: - Output: Always returns 0 + Output: Always returns 0 Errors: ------------------------------------------------------------------------*/ int ResetText(void) @@ -706,10 +707,10 @@ int ResetText(void) Errors: -------------------------------------------------------------------------- Edit History: - 06 Oct 2003 - Chris Watford watford@uiuc.edu - - Removed entries that crashed OCaml - - Removed useless entries - - Added Save ML and Save Transcript + 06 Oct 2003 - Chris Watford watford@uiuc.edu + - Removed entries that crashed OCaml + - Removed useless entries + - Added Save ML and Save Transcript ------------------------------------------------------------------------*/ void HandleCommand(HWND hwnd, WPARAM wParam,LPARAM lParam) { @@ -747,7 +748,7 @@ void HandleCommand(HWND hwnd, WPARAM wParam,LPARAM lParam) CopyToClipboard(hwnd); break; - // updated to save a transcript + // updated to save a transcript case IDM_SAVEAS: fname = SafeMalloc(512); if (GetSaveName(fname,512)) { @@ -756,29 +757,29 @@ void HandleCommand(HWND hwnd, WPARAM wParam,LPARAM lParam) free(fname); break; - // updated to save an ML file - case IDM_SAVE: + // updated to save an ML file + case IDM_SAVE: fname = SafeMalloc(512); if (GetSaveMLName(fname,512)) - { + { SaveML(fname); } free(fname); break; - // updated to work with new history system + // updated to work with new history system case IDM_HISTORY: r = CallDlgProc(HistoryDlgProc,IDD_HISTORY); if (r) - { + { AddLineToControl(GetHistoryLine(r-1)); } break; case IDM_PRINTSU: - // Removed by Chris Watford - // seems to die + // Removed by Chris Watford + // seems to die // CallPrintSetup(); break; @@ -799,7 +800,7 @@ void HandleCommand(HWND hwnd, WPARAM wParam,LPARAM lParam) Undo(hwnd); break; - /* Removed, really not very useful in this IDE + /* Removed, really not very useful in this IDE case IDM_WINDOWTILE: SendMessage(hwndMDIClient,WM_MDITILE,0,0); break; @@ -809,7 +810,7 @@ void HandleCommand(HWND hwnd, WPARAM wParam,LPARAM lParam) case IDM_WINDOWICONS: SendMessage(hwndMDIClient,WM_MDIICONARRANGE,0,0); break; - */ + */ case IDM_EXIT: PostMessage(hwnd,WM_CLOSE,0,0); diff --git a/win32caml/ocaml.c b/win32caml/ocaml.c index 2a2e04a54..04899473f 100644 --- a/win32caml/ocaml.c +++ b/win32caml/ocaml.c @@ -1,7 +1,9 @@ +/***********************************************************************/ /* */ -/* Objective Caml */ +/* OCaml */ /* */ /* Developed by Jacob Navia. */ +/* */ /* Copyright 2001 Institut National de Recherche en Informatique et */ /* en Automatique. All rights reserved. This file is distributed */ /* under the terms of the GNU Library General Public License, with */ @@ -76,10 +78,10 @@ Errors: none ------------------------------------------------------------------------*/ void UpdateStatusBar(LPSTR lpszStatusString, WORD partNumber, WORD displayFlags) { - SendMessage(hWndStatusbar, - SB_SETTEXT, - partNumber | displayFlags, - (LPARAM)lpszStatusString); + SendMessage(hWndStatusbar, + SB_SETTEXT, + partNumber | displayFlags, + (LPARAM)lpszStatusString); } @@ -95,36 +97,36 @@ Errors: If the string is not found nothing will be shown. ------------------------------------------------------------------------*/ LRESULT MsgMenuSelect(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam) { - static char szBuffer[256]; - UINT nStringID = 0; - UINT fuFlags = GET_WM_MENUSELECT_FLAGS(wparam, lparam) & 0xffff; - UINT uCmd = GET_WM_MENUSELECT_CMD(wparam, lparam); - HMENU hMenu = GET_WM_MENUSELECT_HMENU(wparam, lparam); - - szBuffer[0] = 0; // First reset the buffer - if (fuFlags == 0xffff && hMenu == NULL) // Menu has been closed - nStringID = 0; - - else if (fuFlags & MFT_SEPARATOR) // Ignore separators - nStringID = 0; - - else if (fuFlags & MF_POPUP) // Popup menu - { - if (fuFlags & MF_SYSMENU) // System menu - nStringID = IDS_SYSMENU; - else - // Get string ID for popup menu from idPopup array. - nStringID = 0; - } // for MF_POPUP - else // Must be a command item - nStringID = uCmd; // String ID == Command ID - - // Load the string if we have an ID - if (0 != nStringID) - LoadString(hInst, nStringID, szBuffer, sizeof(szBuffer)); - // Finally... send the string to the status bar - UpdateStatusBar(szBuffer, 0, 0); - return 0; + static char szBuffer[256]; + UINT nStringID = 0; + UINT fuFlags = GET_WM_MENUSELECT_FLAGS(wparam, lparam) & 0xffff; + UINT uCmd = GET_WM_MENUSELECT_CMD(wparam, lparam); + HMENU hMenu = GET_WM_MENUSELECT_HMENU(wparam, lparam); + + szBuffer[0] = 0; // First reset the buffer + if (fuFlags == 0xffff && hMenu == NULL) // Menu has been closed + nStringID = 0; + + else if (fuFlags & MFT_SEPARATOR) // Ignore separators + nStringID = 0; + + else if (fuFlags & MF_POPUP) // Popup menu + { + if (fuFlags & MF_SYSMENU) // System menu + nStringID = IDS_SYSMENU; + else + // Get string ID for popup menu from idPopup array. + nStringID = 0; + } // for MF_POPUP + else // Must be a command item + nStringID = uCmd; // String ID == Command ID + + // Load the string if we have an ID + if (0 != nStringID) + LoadString(hInst, nStringID, szBuffer, sizeof(szBuffer)); + // Finally... send the string to the status bar + UpdateStatusBar(szBuffer, 0, 0); + return 0; } /*------------------------------------------------------------------------ @@ -138,7 +140,7 @@ Errors: ------------------------------------------------------------------------*/ static VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime) { - SendMessage(hwndSession, WM_TIMERTICK, 0, 0); + SendMessage(hwndSession, WM_TIMERTICK, 0, 0); } /*------------------------------------------------------------------------ @@ -154,27 +156,27 @@ Errors: ------------------------------------------------------------------------*/ void InitializeStatusBar(HWND hwndParent,int nrOfParts) { - const int cSpaceInBetween = 8; - int ptArray[40]; // Array defining the number of parts/sections - RECT rect; - HDC hDC; + const int cSpaceInBetween = 8; + int ptArray[40]; // Array defining the number of parts/sections + RECT rect; + HDC hDC; - /* * Fill in the ptArray... */ + /* * Fill in the ptArray... */ - hDC = GetDC(hwndParent); - GetClientRect(hwndParent, &rect); + hDC = GetDC(hwndParent); + GetClientRect(hwndParent, &rect); - ptArray[nrOfParts-1] = rect.right; - //---TODO--- Add code to calculate the size of each part of the status - // bar here. + ptArray[nrOfParts-1] = rect.right; + //---TODO--- Add code to calculate the size of each part of the status + // bar here. - ReleaseDC(hwndParent, hDC); - SendMessage(hWndStatusbar, - SB_SETPARTS, - nrOfParts, - (LPARAM)(LPINT)ptArray); + ReleaseDC(hwndParent, hDC); + SendMessage(hWndStatusbar, + SB_SETPARTS, + nrOfParts, + (LPARAM)(LPINT)ptArray); - UpdateStatusBar("Ready", 0, 0); + UpdateStatusBar("Ready", 0, 0); } @@ -188,17 +190,17 @@ Errors: ------------------------------------------------------------------------*/ static BOOL CreateSBar(HWND hwndParent,char *initialText,int nrOfParts) { - hWndStatusbar = CreateStatusWindow(WS_CHILD | WS_VISIBLE | WS_BORDER|SBARS_SIZEGRIP, - initialText, - hwndParent, - IDM_STATUSBAR); - if(hWndStatusbar) - { - InitializeStatusBar(hwndParent,nrOfParts); - return TRUE; - } - - return FALSE; + hWndStatusbar = CreateStatusWindow(WS_CHILD | WS_VISIBLE | WS_BORDER|SBARS_SIZEGRIP, + initialText, + hwndParent, + IDM_STATUSBAR); + if(hWndStatusbar) + { + InitializeStatusBar(hwndParent,nrOfParts); + return TRUE; + } + + return FALSE; } /*------------------------------------------------------------------------ Procedure: InitApplication ID:1 @@ -211,32 +213,32 @@ Errors: ------------------------------------------------------------------------*/ static BOOL InitApplication(void) { - WNDCLASS wc; - - memset(&wc,0,sizeof(WNDCLASS)); - wc.style = CS_HREDRAW|CS_VREDRAW |CS_DBLCLKS ; - wc.lpfnWndProc = (WNDPROC)MainWndProc; - wc.hInstance = hInst; - wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wc.lpszClassName = "inriaWndClass"; - wc.lpszMenuName = MAKEINTRESOURCE(IDMAINMENU); - wc.hCursor = LoadCursor(NULL,IDC_ARROW); - wc.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(OCAML_ICON)); - if (!RegisterClass(&wc)) - return 0; - wc.style = 0; - wc.lpfnWndProc = (WNDPROC)MdiChildWndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 20; - wc.hInstance = hInst; // Owner of this class - wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(OCAML_ICON)); - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color - wc.lpszMenuName = NULL; - wc.lpszClassName = "MdiChildWndClass"; - if (!RegisterClass((LPWNDCLASS)&wc)) - return FALSE; - return 1; + WNDCLASS wc; + + memset(&wc,0,sizeof(WNDCLASS)); + wc.style = CS_HREDRAW|CS_VREDRAW |CS_DBLCLKS ; + wc.lpfnWndProc = (WNDPROC)MainWndProc; + wc.hInstance = hInst; + wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); + wc.lpszClassName = "inriaWndClass"; + wc.lpszMenuName = MAKEINTRESOURCE(IDMAINMENU); + wc.hCursor = LoadCursor(NULL,IDC_ARROW); + wc.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(OCAML_ICON)); + if (!RegisterClass(&wc)) + return 0; + wc.style = 0; + wc.lpfnWndProc = (WNDPROC)MdiChildWndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 20; + wc.hInstance = hInst; // Owner of this class + wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(OCAML_ICON)); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color + wc.lpszMenuName = NULL; + wc.lpszClassName = "MdiChildWndClass"; + if (!RegisterClass((LPWNDCLASS)&wc)) + return FALSE; + return 1; } /*------------------------------------------------------------------------ @@ -248,13 +250,13 @@ Errors: ------------------------------------------------------------------------*/ HWND CreateinriaWndClassWnd(void) { - return CreateWindow("inriaWndClass","OCamlWinPlus v1.9RC4", - WS_MINIMIZEBOX|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_MAXIMIZEBOX|WS_CAPTION|WS_BORDER|WS_SYSMENU|WS_THICKFRAME, - CW_USEDEFAULT,0,CW_USEDEFAULT,0, - NULL, - NULL, - hInst, - NULL); + return CreateWindow("inriaWndClass","OCamlWinPlus v1.9RC4", + WS_MINIMIZEBOX|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_MAXIMIZEBOX|WS_CAPTION|WS_BORDER|WS_SYSMENU|WS_THICKFRAME, + CW_USEDEFAULT,0,CW_USEDEFAULT,0, + NULL, + NULL, + hInst, + NULL); } /*------------------------------------------------------------------------ @@ -267,80 +269,80 @@ Errors: ------------------------------------------------------------------------*/ static HWND MDICmdFileNew(char *title, int show) { - HWND hwndChild; - char rgch[150]; - static int cUntitled; - MDICREATESTRUCT mcs; - - if (title == NULL) - wsprintf(rgch,"Session%d", cUntitled++); - else { - strncpy(rgch,title,149); - rgch[149] = 0; - } - - // Create the MDI child window - - mcs.szClass = "MdiChildWndClass"; // window class name - mcs.szTitle = rgch; // window title - mcs.hOwner = hInst; // owner - mcs.x = CW_USEDEFAULT; // x position - mcs.y = CW_USEDEFAULT; // y position - mcs.cx = CW_USEDEFAULT; // width - mcs.cy = CW_USEDEFAULT; // height - mcs.style = 0; // window style - mcs.lParam = 0; // lparam - - hwndChild = (HWND) SendMessage(hwndMDIClient, - WM_MDICREATE, - 0, - (LPARAM)(LPMDICREATESTRUCT) &mcs); - - if (hwndChild != NULL && show) - ShowWindow(hwndChild, SW_SHOW); - - return hwndChild; + HWND hwndChild; + char rgch[150]; + static int cUntitled; + MDICREATESTRUCT mcs; + + if (title == NULL) + wsprintf(rgch,"Session%d", cUntitled++); + else { + strncpy(rgch,title,149); + rgch[149] = 0; + } + + // Create the MDI child window + + mcs.szClass = "MdiChildWndClass"; // window class name + mcs.szTitle = rgch; // window title + mcs.hOwner = hInst; // owner + mcs.x = CW_USEDEFAULT; // x position + mcs.y = CW_USEDEFAULT; // y position + mcs.cx = CW_USEDEFAULT; // width + mcs.cy = CW_USEDEFAULT; // height + mcs.style = 0; // window style + mcs.lParam = 0; // lparam + + hwndChild = (HWND) SendMessage(hwndMDIClient, + WM_MDICREATE, + 0, + (LPARAM)(LPMDICREATESTRUCT) &mcs); + + if (hwndChild != NULL && show) + ShowWindow(hwndChild, SW_SHOW); + + return hwndChild; } static HWND CreateMdiClient(HWND hwndparent) { - CLIENTCREATESTRUCT ccs = {0}; - HWND hwndMDIClient; - int icount = GetMenuItemCount(GetMenu(hwndparent)); - - // Find window menu where children will be listed - ccs.hWindowMenu = GetSubMenu(GetMenu(hwndparent), icount-2); - ccs.idFirstChild = IDM_WINDOWCHILD; - - // Create the MDI client filling the client area - hwndMDIClient = CreateWindow("mdiclient", - NULL, - WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | - WS_HSCROLL, - 0, 0, 0, 0, - hwndparent, - (HMENU)0xCAC, - hInst, - (LPVOID)&ccs); - - ShowWindow(hwndMDIClient, SW_SHOW); - - return hwndMDIClient; + CLIENTCREATESTRUCT ccs = {0}; + HWND hwndMDIClient; + int icount = GetMenuItemCount(GetMenu(hwndparent)); + + // Find window menu where children will be listed + ccs.hWindowMenu = GetSubMenu(GetMenu(hwndparent), icount-2); + ccs.idFirstChild = IDM_WINDOWCHILD; + + // Create the MDI client filling the client area + hwndMDIClient = CreateWindow("mdiclient", + NULL, + WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | + WS_HSCROLL, + 0, 0, 0, 0, + hwndparent, + (HMENU)0xCAC, + hInst, + (LPVOID)&ccs); + + ShowWindow(hwndMDIClient, SW_SHOW); + + return hwndMDIClient; } void GotoEOF(void) { - HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); - int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0); - int lineindex = SendMessage(hEdit,EM_LINEINDEX,linesCount-1,0); - int lastLineLength = SendMessage(hEdit,EM_LINELENGTH,linesCount-1,0); + HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0); + int lineindex = SendMessage(hEdit,EM_LINEINDEX,linesCount-1,0); + int lastLineLength = SendMessage(hEdit,EM_LINELENGTH,linesCount-1,0); - lineindex += lastLineLength; - SendMessage(hEdit,EM_SETSEL,lineindex,lineindex); + lineindex += lastLineLength; + SendMessage(hEdit,EM_SETSEL,lineindex,lineindex); } /*------------------------------------------------------------------------ Procedure: GotoPrompt ID:1 -Author: Chris Watford watford@uiuc.edu +Author: Chris Watford watford@uiuc.edu Purpose: Puts the cursor on the prompt line right after the '# ' Input: Output: @@ -348,190 +350,190 @@ Errors: ------------------------------------------------------------------------*/ void GotoPrompt(void) { - HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); - int lineindex = SendMessage(hEdit,EM_LINEINDEX,LastPromptPosition.line,0)+2; - SendMessage(hEdit,EM_SETSEL,lineindex,lineindex); + HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + int lineindex = SendMessage(hEdit,EM_LINEINDEX,LastPromptPosition.line,0)+2; + SendMessage(hEdit,EM_SETSEL,lineindex,lineindex); } int GetCurLineIndex(HWND hEdit) { - return SendMessage(hEdit,EM_LINEFROMCHAR,(WPARAM)-1,0); + return SendMessage(hEdit,EM_LINEFROMCHAR,(WPARAM)-1,0); } int GetNumberOfLines(HWND hEdit) { - return SendMessage(hEdit,EM_GETLINECOUNT,0,0); + return SendMessage(hEdit,EM_GETLINECOUNT,0,0); } static int GetWordUnderCursor(HWND hwndEditControl,char *buf,int len) { - char *line,*p,*pstart,*pend; - int lineidx,start,end,length,offset,cursorpos,startingChar; - - SendMessage(hwndEditControl,EM_GETSEL,(WPARAM)&start,(LPARAM)&end); - lineidx = SendMessage(hwndEditControl,EM_EXLINEFROMCHAR,0,start); - startingChar = SendMessage(hwndEditControl,EM_LINEINDEX,lineidx,0); - start -= startingChar; - end -= startingChar; - lineidx = SendMessage(hwndEditControl,EM_LINEFROMCHAR,start,0); - length = SendMessage(hwndEditControl,EM_LINELENGTH,lineidx,0); - offset = SendMessage(hwndEditControl,EM_LINEINDEX,lineidx,0); - line = SafeMalloc(length+1); - memset(line,0,length+1); - *(unsigned short *)line = length; - SendMessage(hwndEditControl,EM_GETLINE,lineidx,(LPARAM)line); - cursorpos = start-offset; - p = line + cursorpos; - pstart = p; - while (*pstart - && *pstart != ' ' - && *pstart != '\t' - && *pstart != '(' - && pstart > line) - pstart--; - pend = p; - while (*pend - && *pend != ' ' - && *pend != '\t' - && *pend != '(' - && pend < line + length) - pend++; - if (*pstart == ' ' || *pstart == '\t') - pstart++; - if (*pend == ' ' || *pend == '\t') - pend--; - memcpy(buf,pstart,1+pend-pstart); - buf[pend-pstart] = 0; - free(line); - return 1; + char *line,*p,*pstart,*pend; + int lineidx,start,end,length,offset,cursorpos,startingChar; + + SendMessage(hwndEditControl,EM_GETSEL,(WPARAM)&start,(LPARAM)&end); + lineidx = SendMessage(hwndEditControl,EM_EXLINEFROMCHAR,0,start); + startingChar = SendMessage(hwndEditControl,EM_LINEINDEX,lineidx,0); + start -= startingChar; + end -= startingChar; + lineidx = SendMessage(hwndEditControl,EM_LINEFROMCHAR,start,0); + length = SendMessage(hwndEditControl,EM_LINELENGTH,lineidx,0); + offset = SendMessage(hwndEditControl,EM_LINEINDEX,lineidx,0); + line = SafeMalloc(length+1); + memset(line,0,length+1); + *(unsigned short *)line = length; + SendMessage(hwndEditControl,EM_GETLINE,lineidx,(LPARAM)line); + cursorpos = start-offset; + p = line + cursorpos; + pstart = p; + while (*pstart + && *pstart != ' ' + && *pstart != '\t' + && *pstart != '(' + && pstart > line) + pstart--; + pend = p; + while (*pend + && *pend != ' ' + && *pend != '\t' + && *pend != '(' + && pend < line + length) + pend++; + if (*pstart == ' ' || *pstart == '\t') + pstart++; + if (*pend == ' ' || *pend == '\t') + pend--; + memcpy(buf,pstart,1+pend-pstart); + buf[pend-pstart] = 0; + free(line); + return 1; } /*------------------------------------------------------------------------ Procedure: GetLastLine ID:1 Purpose: Gets the data in the line containing the cursor to - the interpreter. + the interpreter. Input: The edit control window handle Output: None explicit Errors: None ------------------------------------------------------------------------*/ char* GetLastLine(HWND hEdit) { - int curline = GetCurLineIndex(hEdit); - char *linebuffer = (char*)SafeMalloc(2048*sizeof(char)); - int n; - int linescount = GetNumberOfLines(hEdit); + int curline = GetCurLineIndex(hEdit); + char *linebuffer = (char*)SafeMalloc(2048*sizeof(char)); + int n; + int linescount = GetNumberOfLines(hEdit); - *(unsigned short *)linebuffer = 2047; - n = SendMessage(hEdit,EM_GETLINE,curline,(LPARAM)linebuffer); + *(unsigned short *)linebuffer = 2047; + n = SendMessage(hEdit,EM_GETLINE,curline,(LPARAM)linebuffer); - if (n >= 2 && linebuffer[0] == '#' && linebuffer[1] == ' ') { - n -= 2; - memmove(linebuffer, linebuffer+2, n); - } + if (n >= 2 && linebuffer[0] == '#' && linebuffer[1] == ' ') { + n -= 2; + memmove(linebuffer, linebuffer+2, n); + } - linebuffer[n] = '\0'; + linebuffer[n] = '\0'; - return linebuffer; + return linebuffer; } void DoHelp(HWND hwnd) { - char word[256]; - GetWordUnderCursor(hwnd,word,sizeof(word)); - MessageBox(NULL,word,"Aide pour:",MB_OK); + char word[256]; + GetWordUnderCursor(hwnd,word,sizeof(word)); + MessageBox(NULL,word,"Aide pour:",MB_OK); } /*------------------------------------------------------------------------ Procedure: RewriteCurrentEditBuffer ID:1 Purpose: Rewrites what is at the prompt with the current contents of - the edit buffer + the edit buffer Input: None Output: None explicit Errors: None ------------------------------------------------------------------------*/ void RewriteCurrentEditBuffer(void) { - // get the editbox's handle - HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); - - // calculate what to highlight - int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0); - int lineindex = SendMessage(hEdit,EM_LINEINDEX,LastPromptPosition.line,0) + 2; - int lastLine = SendMessage(hEdit,EM_LINEINDEX,linesCount-1,0) + SendMessage(hEdit,EM_LINELENGTH,linesCount-1,0) + 100; - - // delete the current text - SendMessage(hEdit, EM_SETSEL, (WPARAM)lineindex, (LPARAM)lastLine); - SendMessage(hEdit, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)""); - - { - // loop through each line in the edit buffer and add it to the control - LineList* line = CurrentEditBuffer->Lines; - for(; line != NULL; line = line->Next) - { - // if there is a line before me, add a newline - if(line->Prev != NULL) - SendMessage(hEdit, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)"\r\n"); - - // add the line - SendMessage(hEdit, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)line->Text); - } - } + // get the editbox's handle + HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + + // calculate what to highlight + int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0); + int lineindex = SendMessage(hEdit,EM_LINEINDEX,LastPromptPosition.line,0) + 2; + int lastLine = SendMessage(hEdit,EM_LINEINDEX,linesCount-1,0) + SendMessage(hEdit,EM_LINELENGTH,linesCount-1,0) + 100; + + // delete the current text + SendMessage(hEdit, EM_SETSEL, (WPARAM)lineindex, (LPARAM)lastLine); + SendMessage(hEdit, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)""); + + { + // loop through each line in the edit buffer and add it to the control + LineList* line = CurrentEditBuffer->Lines; + for(; line != NULL; line = line->Next) + { + // if there is a line before me, add a newline + if(line->Prev != NULL) + SendMessage(hEdit, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)"\r\n"); + + // add the line + SendMessage(hEdit, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)line->Text); + } + } } /*------------------------------------------------------------------------ Procedure: RefreshCurrentEditBuffer ID:1 Purpose: Rewrites what is in the CurrentEditBuffer with what is - actually there + actually there Input: None Output: None explicit Errors: None ------------------------------------------------------------------------*/ void RefreshCurrentEditBuffer(void) { - // get the editbox's handle - HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); - - // get the last line index - int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0) - 1; - int i = 0, n = 0; - - // where to hold the line we grab - char *linebuffer = (char*)SafeMalloc(2048*sizeof(char)); - *(unsigned short *)linebuffer = 2047; - - editbuffer_destroy(CurrentEditBuffer); - CurrentEditBuffer = editbuffer_new(); - - // loop through each line updating or adding it to the current edit buffer - for( ; (i + LastPromptPosition.line) <= linesCount; i++) - { - n = SendMessage(hEdit, EM_GETLINE, (i + LastPromptPosition.line), (LPARAM)linebuffer); - - if ((n >= 2) && (linebuffer[0] == '#') && (linebuffer[1] == ' ')) { - n -= 2; - memmove(linebuffer, linebuffer+2, n); - } - - linebuffer[n] = '\0'; - - { // remove line breaks and feeds - char* ln = linebuffer; - - while((*ln) != 0) - { - switch((*ln)) - { - case '\r': - case '\n': - (*ln) = ' '; - } - - ln++; - } - } - - editbuffer_addline(CurrentEditBuffer, linebuffer); - } + // get the editbox's handle + HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + + // get the last line index + int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0) - 1; + int i = 0, n = 0; + + // where to hold the line we grab + char *linebuffer = (char*)SafeMalloc(2048*sizeof(char)); + *(unsigned short *)linebuffer = 2047; + + editbuffer_destroy(CurrentEditBuffer); + CurrentEditBuffer = editbuffer_new(); + + // loop through each line updating or adding it to the current edit buffer + for( ; (i + LastPromptPosition.line) <= linesCount; i++) + { + n = SendMessage(hEdit, EM_GETLINE, (i + LastPromptPosition.line), (LPARAM)linebuffer); + + if ((n >= 2) && (linebuffer[0] == '#') && (linebuffer[1] == ' ')) { + n -= 2; + memmove(linebuffer, linebuffer+2, n); + } + + linebuffer[n] = '\0'; + + { // remove line breaks and feeds + char* ln = linebuffer; + + while((*ln) != 0) + { + switch((*ln)) + { + case '\r': + case '\n': + (*ln) = ' '; + } + + ln++; + } + } + + editbuffer_addline(CurrentEditBuffer, linebuffer); + } } /*------------------------------------------------------------------------ @@ -542,42 +544,42 @@ Output: None explicit Errors: None -------------------------------------------------------------------------- Edit History: - 17 Sept 2003 - Chris Watford watford@uiuc.edu - - Added this as a helper function - 18 Sept 2003 - Chris Watford watford@uiuc.edu - - Corrected doubly linked list problems + 17 Sept 2003 - Chris Watford watford@uiuc.edu + - Added this as a helper function + 18 Sept 2003 - Chris Watford watford@uiuc.edu + - Corrected doubly linked list problems ------------------------------------------------------------------------*/ void NextHistoryEntry(void) { - // out of bounds, put it back into bounds - if(historyEntry == NULL && History == NULL) - { - return; - } else if (historyEntry == NULL && History != NULL) { - historyEntry = History; - } else { - if(historyEntry->Next == NULL) - return; - - historyEntry = historyEntry->Next; - } - - // if its valid - if(historyEntry != NULL) - { - // copy the history entry to a new buffer - EditBuffer* newBuf = editbuffer_copy(historyEntry->Statement); - - // destroy the old buffer - editbuffer_destroy(CurrentEditBuffer); - - // setup the current one to the copy - CurrentEditBuffer = newBuf; - - // rewrite the old one and go to the prompt - RewriteCurrentEditBuffer(); - GotoPrompt(); - } + // out of bounds, put it back into bounds + if(historyEntry == NULL && History == NULL) + { + return; + } else if (historyEntry == NULL && History != NULL) { + historyEntry = History; + } else { + if(historyEntry->Next == NULL) + return; + + historyEntry = historyEntry->Next; + } + + // if its valid + if(historyEntry != NULL) + { + // copy the history entry to a new buffer + EditBuffer* newBuf = editbuffer_copy(historyEntry->Statement); + + // destroy the old buffer + editbuffer_destroy(CurrentEditBuffer); + + // setup the current one to the copy + CurrentEditBuffer = newBuf; + + // rewrite the old one and go to the prompt + RewriteCurrentEditBuffer(); + GotoPrompt(); + } } /*------------------------------------------------------------------------ @@ -588,312 +590,312 @@ Output: None explicit Errors: None -------------------------------------------------------------------------- Edit History: - 17 Sept 2003 - Chris Watford watford@uiuc.edu - - Added this as a helper function - 18 Sept 2003 - Chris Watford watford@uiuc.edu - - Corrected doubly linked list problems + 17 Sept 2003 - Chris Watford watford@uiuc.edu + - Added this as a helper function + 18 Sept 2003 - Chris Watford watford@uiuc.edu + - Corrected doubly linked list problems ------------------------------------------------------------------------*/ void PrevHistoryEntry(void) { - // out of bounds, put it back into bounds - if(historyEntry == NULL || History == NULL) - { - return; - } else { - if(historyEntry->Prev == NULL) - return; - - historyEntry = historyEntry->Prev; - } - - // if its valid - if(historyEntry != NULL) - { - // copy the history entry to a new buffer - EditBuffer* newBuf = editbuffer_copy(historyEntry->Statement); - - // destroy the old buffer - editbuffer_destroy(CurrentEditBuffer); - - // setup the current one to the copy - CurrentEditBuffer = newBuf; - - // rewrite the old one and go to the prompt - RewriteCurrentEditBuffer(); - GotoPrompt(); - } + // out of bounds, put it back into bounds + if(historyEntry == NULL || History == NULL) + { + return; + } else { + if(historyEntry->Prev == NULL) + return; + + historyEntry = historyEntry->Prev; + } + + // if its valid + if(historyEntry != NULL) + { + // copy the history entry to a new buffer + EditBuffer* newBuf = editbuffer_copy(historyEntry->Statement); + + // destroy the old buffer + editbuffer_destroy(CurrentEditBuffer); + + // setup the current one to the copy + CurrentEditBuffer = newBuf; + + // rewrite the old one and go to the prompt + RewriteCurrentEditBuffer(); + GotoPrompt(); + } } /*------------------------------------------------------------------------ Procedure: SubClassEdit ID:1 Purpose: Handles messages to the editbox -Input: -Output: +Input: +Output: Errors: -------------------------------------------------------------------------- Edit History: - 14 Sept 2003 - Chris Watford watford@uiuc.edu - - Setup handler for up and down arrows - 15 Sept 2003 - Chris Watford watford@uiuc.edu - - Setup framework for history on up arrow - - Saves lines you move off of in the edit buffer - 16 Sept 2003 - Chris Watford watford@uiuc.edu - - Proper handling of newline message finished - - Fixed ENTER on middle of interior line, moves cursor to the end - and sends the line - - Setup the copying and destroying of the old buffer - - Included buffer rewrite - 17 Sept 2003 - Chris Watford watford@uiuc.edu - - Added C-p/C-n support - - Changed UpArrow to C-UpArrow so as to not confuse users - 18 Sept 2003 - Chris Watford watford@uiuc.edu - - Added Left and Right arrow line saving - - Added backspace and delete line saving and removing - - Fixed history scrolling - 21 Sept 2003 - Chris Watford watford@uiuc.edu - - Fixed pasting errors associated with lines being out of bounds - for the buffer - - Added error handling, possibly able to handle it diff down the - line - - Removed C-Up/C-Dn for history scrolling, buggy at best on my - machine + 14 Sept 2003 - Chris Watford watford@uiuc.edu + - Setup handler for up and down arrows + 15 Sept 2003 - Chris Watford watford@uiuc.edu + - Setup framework for history on up arrow + - Saves lines you move off of in the edit buffer + 16 Sept 2003 - Chris Watford watford@uiuc.edu + - Proper handling of newline message finished + - Fixed ENTER on middle of interior line, moves cursor to the end + and sends the line + - Setup the copying and destroying of the old buffer + - Included buffer rewrite + 17 Sept 2003 - Chris Watford watford@uiuc.edu + - Added C-p/C-n support + - Changed UpArrow to C-UpArrow so as to not confuse users + 18 Sept 2003 - Chris Watford watford@uiuc.edu + - Added Left and Right arrow line saving + - Added backspace and delete line saving and removing + - Fixed history scrolling + 21 Sept 2003 - Chris Watford watford@uiuc.edu + - Fixed pasting errors associated with lines being out of bounds + for the buffer + - Added error handling, possibly able to handle it diff down the + line + - Removed C-Up/C-Dn for history scrolling, buggy at best on my + machine ------------------------------------------------------------------------*/ static LRESULT CALLBACK SubClassEdit(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2) { - LRESULT r; - int postit=0,nl; - - if (msg == WM_CHAR && mp1 == '\r') { - if (!busy) { - r = GetCurLineIndex(hwnd); - nl = GetNumberOfLines(hwnd); - - // if we're not the last line - if (r != nl-1) - { - // update or add us, we might not have any lines in the edit buffer - editbuffer_updateoraddline(CurrentEditBuffer, r-LastPromptPosition.line, GetLastLine(hwnd)); - - // scroll to the end, add CrLf then post the newline message - GotoEOF(); - AddStringToControl("\r\n"); - PostMessage(GetParent(hwnd),WM_NEWLINE,0,0); - return 0; - } - - CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); - CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); - - postit = 1; - } - - } - else if (msg == WM_CHAR && mp1 == (char)0x08) { - int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; - int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); - int nextline = 0; - int curpoint = 0; - - SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); - nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint - 1),0); - - if(curpoint <= lineindex) - { - return 0; - } else if(nextline != curline) { - // delete the line we're on - - // grab the index - curline -= LastPromptPosition.line; - - // kill it - editbuffer_removeline(CurrentEditBuffer, curline); - } - } - else if (msg == WM_KEYDOWN && mp1 == VK_F1) { - DoHelp(hwnd); - } - else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && mp1 == VK_UP) { - int curline = GetCurLineIndex(hwnd); - - /*if((msg == WM_KEYDOWN) && (GetKeyState(VK_CONTROL) && 0x8000)) - { // go forward once in history - NextHistoryEntry(); - return 0; - } else */ - if((curline > LastPromptPosition.line) && (curline <= (LastPromptPosition.line + CurrentEditBuffer->LineCount))) - { - // update current line - if (msg == WM_KEYDOWN) - { - int lineidx = (curline - LastPromptPosition.line); - - CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); - CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); - - // we may have to add this line, otherwise update it - editbuffer_updateoraddline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); - } - } else { - return 0; - } - } - else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_LEFT)) { - int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; - int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); - int nextline = 0; - int curpoint = 0; - - SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); - nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint - 1),0); - - if(curpoint <= lineindex) - { // no left arrow to the left of the prompt - return 0; - } else if(nextline != curline) { - // update current line - if (msg == WM_KEYDOWN) - { - int lineidx = (curline - LastPromptPosition.line); - - CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); - CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); - - // we may have to add this line, otherwise update it - editbuffer_updateoraddline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); - - CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_HOME,1); - CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_HOME,1); - } - } - } - else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_DOWN)) { - int curline = GetCurLineIndex(hwnd); - - /*if((msg == WM_KEYDOWN) && (GetKeyState(VK_CONTROL) && 0x8000)) - { // go back once in history - PrevHistoryEntry(); - return 0; - } else*/ - if((curline >= LastPromptPosition.line) && (curline < (LastPromptPosition.line + CurrentEditBuffer->LineCount))) - { - // We don't post the newline, but instead update the current line - if (msg == WM_KEYDOWN) - { - int lineidx = (curline - LastPromptPosition.line); - - CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); - CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); - - editbuffer_updateline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); - } - } else { - return 0; - } - } - else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_RIGHT)) { - int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 1; - int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); - int nextline = 0; - int curpoint = 0; - - SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); - nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint + 2),0); - - if(curpoint <= lineindex) - { // no movement behind the prompt - return 0; - } else if((nextline != curline) && (msg = WM_KEYDOWN)) { - int lineidx = (curline - LastPromptPosition.line); - - CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); - CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); - - editbuffer_updateline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); - } - } - else if ((msg == WM_KEYDOWN) && (mp1 == VK_PRIOR) && (GetKeyState(VK_CONTROL) && 0x8000)) { - // C-p - NextHistoryEntry(); - return 0; - } - else if ((msg == WM_KEYDOWN) && (mp1 == VK_NEXT) && (GetKeyState(VK_CONTROL) && 0x8000)) { - // C-n - PrevHistoryEntry(); - return 0; - } - else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_DELETE)) { - // see if we're the last char on the line, if so delete the next line - // don't allow deleting left of the prompt - int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; - int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); - int nextline = 0; - int curpoint = 0; - - SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); - nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint + 2),0); - - if(curpoint < lineindex) - { // no chomping behind the prompt - return 0; - } else if(nextline != curline) { - // deleting - // grab the next line index - curline -= LastPromptPosition.line; - - // kill it - editbuffer_removeline(CurrentEditBuffer, curline+1); - } - } - else if (msg == WM_PASTE) { - // if they paste text, allow it - r = CallWindowProc(lpEProc, hwnd, msg, mp1, mp2); - - // update the current edit buffer - RefreshCurrentEditBuffer(); - - return r; - } - - // handle errors - switch(msg) - { - case WM_SYNTAXERROR: - case WM_ILLEGALCHAR: - case WM_UNBOUNDVAL: - { // currently I handle them all the same - // get the start of the line - int start = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; - - // get the statement that error'd - NextHistoryEntry(); - - // tell the history that the last line errored - if(History != NULL) - if(History->Statement != NULL) - History->Statement->isCorrect = FALSE; - - // highlight the offending chars - SendMessage(hwnd,EM_SETSEL,(WPARAM)(start + mp1), (LPARAM)(start + mp2)); - - return 0; - } - } - - r = CallWindowProc(lpEProc, hwnd, msg, mp1, mp2); - - if (postit) - PostMessage(GetParent(hwnd),WM_NEWLINE,0,0); - - return r; + LRESULT r; + int postit=0,nl; + + if (msg == WM_CHAR && mp1 == '\r') { + if (!busy) { + r = GetCurLineIndex(hwnd); + nl = GetNumberOfLines(hwnd); + + // if we're not the last line + if (r != nl-1) + { + // update or add us, we might not have any lines in the edit buffer + editbuffer_updateoraddline(CurrentEditBuffer, r-LastPromptPosition.line, GetLastLine(hwnd)); + + // scroll to the end, add CrLf then post the newline message + GotoEOF(); + AddStringToControl("\r\n"); + PostMessage(GetParent(hwnd),WM_NEWLINE,0,0); + return 0; + } + + CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); + CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); + + postit = 1; + } + + } + else if (msg == WM_CHAR && mp1 == (char)0x08) { + int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; + int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); + int nextline = 0; + int curpoint = 0; + + SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); + nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint - 1),0); + + if(curpoint <= lineindex) + { + return 0; + } else if(nextline != curline) { + // delete the line we're on + + // grab the index + curline -= LastPromptPosition.line; + + // kill it + editbuffer_removeline(CurrentEditBuffer, curline); + } + } + else if (msg == WM_KEYDOWN && mp1 == VK_F1) { + DoHelp(hwnd); + } + else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && mp1 == VK_UP) { + int curline = GetCurLineIndex(hwnd); + + /*if((msg == WM_KEYDOWN) && (GetKeyState(VK_CONTROL) && 0x8000)) + { // go forward once in history + NextHistoryEntry(); + return 0; + } else */ + if((curline > LastPromptPosition.line) && (curline <= (LastPromptPosition.line + CurrentEditBuffer->LineCount))) + { + // update current line + if (msg == WM_KEYDOWN) + { + int lineidx = (curline - LastPromptPosition.line); + + CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); + CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); + + // we may have to add this line, otherwise update it + editbuffer_updateoraddline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); + } + } else { + return 0; + } + } + else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_LEFT)) { + int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; + int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); + int nextline = 0; + int curpoint = 0; + + SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); + nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint - 1),0); + + if(curpoint <= lineindex) + { // no left arrow to the left of the prompt + return 0; + } else if(nextline != curline) { + // update current line + if (msg == WM_KEYDOWN) + { + int lineidx = (curline - LastPromptPosition.line); + + CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); + CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); + + // we may have to add this line, otherwise update it + editbuffer_updateoraddline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); + + CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_HOME,1); + CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_HOME,1); + } + } + } + else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_DOWN)) { + int curline = GetCurLineIndex(hwnd); + + /*if((msg == WM_KEYDOWN) && (GetKeyState(VK_CONTROL) && 0x8000)) + { // go back once in history + PrevHistoryEntry(); + return 0; + } else*/ + if((curline >= LastPromptPosition.line) && (curline < (LastPromptPosition.line + CurrentEditBuffer->LineCount))) + { + // We don't post the newline, but instead update the current line + if (msg == WM_KEYDOWN) + { + int lineidx = (curline - LastPromptPosition.line); + + CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); + CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); + + editbuffer_updateline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); + } + } else { + return 0; + } + } + else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_RIGHT)) { + int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 1; + int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); + int nextline = 0; + int curpoint = 0; + + SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); + nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint + 2),0); + + if(curpoint <= lineindex) + { // no movement behind the prompt + return 0; + } else if((nextline != curline) && (msg = WM_KEYDOWN)) { + int lineidx = (curline - LastPromptPosition.line); + + CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); + CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); + + editbuffer_updateline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); + } + } + else if ((msg == WM_KEYDOWN) && (mp1 == VK_PRIOR) && (GetKeyState(VK_CONTROL) && 0x8000)) { + // C-p + NextHistoryEntry(); + return 0; + } + else if ((msg == WM_KEYDOWN) && (mp1 == VK_NEXT) && (GetKeyState(VK_CONTROL) && 0x8000)) { + // C-n + PrevHistoryEntry(); + return 0; + } + else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_DELETE)) { + // see if we're the last char on the line, if so delete the next line + // don't allow deleting left of the prompt + int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; + int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); + int nextline = 0; + int curpoint = 0; + + SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); + nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint + 2),0); + + if(curpoint < lineindex) + { // no chomping behind the prompt + return 0; + } else if(nextline != curline) { + // deleting + // grab the next line index + curline -= LastPromptPosition.line; + + // kill it + editbuffer_removeline(CurrentEditBuffer, curline+1); + } + } + else if (msg == WM_PASTE) { + // if they paste text, allow it + r = CallWindowProc(lpEProc, hwnd, msg, mp1, mp2); + + // update the current edit buffer + RefreshCurrentEditBuffer(); + + return r; + } + + // handle errors + switch(msg) + { + case WM_SYNTAXERROR: + case WM_ILLEGALCHAR: + case WM_UNBOUNDVAL: + { // currently I handle them all the same + // get the start of the line + int start = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; + + // get the statement that error'd + NextHistoryEntry(); + + // tell the history that the last line errored + if(History != NULL) + if(History->Statement != NULL) + History->Statement->isCorrect = FALSE; + + // highlight the offending chars + SendMessage(hwnd,EM_SETSEL,(WPARAM)(start + mp1), (LPARAM)(start + mp2)); + + return 0; + } + } + + r = CallWindowProc(lpEProc, hwnd, msg, mp1, mp2); + + if (postit) + PostMessage(GetParent(hwnd),WM_NEWLINE,0,0); + + return r; } static void SubClassEditField(HWND hwnd) { - if (lpEProc == NULL) { - lpEProc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC); - } - SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) SubClassEdit); + if (lpEProc == NULL) { + lpEProc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC); + } + SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) SubClassEdit); } /*------------------------------------------------------------------------ @@ -909,42 +911,42 @@ REMOVED! ------------------------------------------------------------------------*/ void SendLastLine(HWND hEdit) { -/* int curline = GetCurLineIndex(hEdit); - char *p,linebuffer[2048]; - int n; - int linescount = GetNumberOfLines(hEdit); - - *(unsigned short *)linebuffer = sizeof(linebuffer)-1; - if (curline != linescount-1) - n = SendMessage(hEdit,EM_GETLINE,curline,(LPARAM)linebuffer); - else - n = SendMessage(hEdit,EM_GETLINE,curline-1,(LPARAM)linebuffer); - if (n >= 2 && linebuffer[0] == '#' && linebuffer[1] == ' ') { - n -= 2; - memmove(linebuffer, linebuffer+2, n); - } - linebuffer[n] = 0; - - // Record user input! - AddToHistory(linebuffer); - linebuffer[n] = '\n'; - linebuffer[n+1] = 0; - WriteToPipe(linebuffer); - if (curline != linescount-1) { - // Copy the line sent to the end of the text - p = strrchr(linebuffer,'\n'); - if (p) { - *p = 0; - } - busy = 1; - AddLineToControl(linebuffer); - busy = 0; - }*/ +/* int curline = GetCurLineIndex(hEdit); + char *p,linebuffer[2048]; + int n; + int linescount = GetNumberOfLines(hEdit); + + *(unsigned short *)linebuffer = sizeof(linebuffer)-1; + if (curline != linescount-1) + n = SendMessage(hEdit,EM_GETLINE,curline,(LPARAM)linebuffer); + else + n = SendMessage(hEdit,EM_GETLINE,curline-1,(LPARAM)linebuffer); + if (n >= 2 && linebuffer[0] == '#' && linebuffer[1] == ' ') { + n -= 2; + memmove(linebuffer, linebuffer+2, n); + } + linebuffer[n] = 0; + + // Record user input! + AddToHistory(linebuffer); + linebuffer[n] = '\n'; + linebuffer[n+1] = 0; + WriteToPipe(linebuffer); + if (curline != linescount-1) { + // Copy the line sent to the end of the text + p = strrchr(linebuffer,'\n'); + if (p) { + *p = 0; + } + busy = 1; + AddLineToControl(linebuffer); + busy = 0; + }*/ } /*------------------------------------------------------------------------ Procedure: SendLastEditBuffer ID:1 -Author: Chris Watford watford@uiuc.edu +Author: Chris Watford watford@uiuc.edu Purpose: Sends an edit buffer to the pipe Input: Output: @@ -952,231 +954,231 @@ Errors: -------------------------------------------------------------------------- Edit History: 7 Aug 2004 - Chris Watford christopher.watford@gmail.com - - Fixed error where SendLastEditBuffer sent waaaay too many - newlines which completely broke the underlying connection to the - ocaml.exe pipe - 15 Sept 2003 - Chris Watford watford@uiuc.edu - - Sends line to the pipe and adds newline to the end + - Fixed error where SendLastEditBuffer sent waaaay too many + newlines which completely broke the underlying connection to the + ocaml.exe pipe + 15 Sept 2003 - Chris Watford watford@uiuc.edu + - Sends line to the pipe and adds newline to the end ------------------------------------------------------------------------*/ void SendLastEditBuffer(HWND hwndChild) { - char* line = editbuffer_getasbuffer(CurrentEditBuffer); - int l = strlen(line) - 1; - char* linebuffer = (char*)SafeMalloc(l+2); - - // save current edit buffer to history and create a new blank edit buffer - CurrentEditBuffer->isCorrect = TRUE; - AddToHistory(CurrentEditBuffer); - CurrentEditBuffer = (EditBuffer*)SafeMalloc(sizeof(EditBuffer)); - CurrentEditBuffer->LineCount = 0; - CurrentEditBuffer->Lines = NULL; - - // trim and add the newline to the end - strncpy(linebuffer, line, l+1); - while((linebuffer[l] == '\n' || linebuffer[l] == '\r') && (l >= 0)) - { - linebuffer[l--] = '\0'; - } - - linebuffer[l+1] = '\n'; - linebuffer[l+2] = '\0'; - - // save line to the pipe - WriteToPipe(linebuffer); + char* line = editbuffer_getasbuffer(CurrentEditBuffer); + int l = strlen(line) - 1; + char* linebuffer = (char*)SafeMalloc(l+2); + + // save current edit buffer to history and create a new blank edit buffer + CurrentEditBuffer->isCorrect = TRUE; + AddToHistory(CurrentEditBuffer); + CurrentEditBuffer = (EditBuffer*)SafeMalloc(sizeof(EditBuffer)); + CurrentEditBuffer->LineCount = 0; + CurrentEditBuffer->Lines = NULL; + + // trim and add the newline to the end + strncpy(linebuffer, line, l+1); + while((linebuffer[l] == '\n' || linebuffer[l] == '\r') && (l >= 0)) + { + linebuffer[l--] = '\0'; + } + + linebuffer[l+1] = '\n'; + linebuffer[l+2] = '\0'; + + // save line to the pipe + WriteToPipe(linebuffer); } /*------------------------------------------------------------------------ Procedure: SendingFullCommand ID:1 -Author: Chris Watford watford@uiuc.edu -Purpose: Returns if the command being sent +Author: Chris Watford watford@uiuc.edu +Purpose: Returns if the command being sent Input: The edit control window handle Output: None explicit Errors: None -------------------------------------------------------------------------- Edit History: - 7 Aug 2004 - Chris Watford christopher.watford@gmail.com - - Fixed bug #2932 where many carraige returns were sent and it came - back with a null pointer error due to a fault of not checking if - the line returned was NULL - 13 Oct 2003 - Chris Watford watford@uiuc.edu - - Solved the error when you have a malformed comment in the buffer + 7 Aug 2004 - Chris Watford christopher.watford@gmail.com + - Fixed bug #2932 where many carraige returns were sent and it came + back with a null pointer error due to a fault of not checking if + the line returned was NULL + 13 Oct 2003 - Chris Watford watford@uiuc.edu + - Solved the error when you have a malformed comment in the buffer ------------------------------------------------------------------------*/ BOOL SendingFullCommand(void) { - // if there is a ;; on the line, return true - char *line = editbuffer_getasline(CurrentEditBuffer); - char *firstComment, *firstSemiColonSemiColon, *firstQuote; - - if(line == NULL) - { - return FALSE; - } - - firstComment = strstr(line, "(*"); - firstSemiColonSemiColon = strstr(line, ";;"); - firstQuote = strstr(line, "\""); - - // easy case :D - if(firstSemiColonSemiColon == NULL) - { - free(line); - return FALSE; - } - - // if there are no comments - if(firstComment == NULL) - { - // if there are no quotations used - if(firstQuote == NULL) - { - BOOL r = (firstSemiColonSemiColon != NULL); - free(line); - return r; - } else { - // we need to first check if the ;; is before the \", since the \" - // won't matter if its before the semicolonsemicolon - if(firstQuote < firstSemiColonSemiColon) - { - // the quote is before the ;;, we need to make sure its terminated - // also we have to check for escaped quotes, le sigh! - char *c = firstQuote+1; - BOOL in_quote = TRUE; - - // in-quote determiner loop - while(c[0] != '\0') - { - // are we a backslash? - if(c[0] == '\\') - { - // ignore the next character - c++; - } - else - { - // are we a quote? - if(c[0] == '"') - { - in_quote = !in_quote; - } - } - - c++; - } - - free(line); - return !in_quote; - } else { - BOOL r = (firstSemiColonSemiColon != NULL); - free(line); - return r; - } - } - } else { - // we have to search through finding all comments - - // a neat little trick we can do is compare the point at which - // the ;; is and where the first (* can be found, if the ;; is - // before the (* ocaml.exe ignores the comment - if((unsigned int)firstSemiColonSemiColon < (unsigned int)firstComment) - { - free(line); - return TRUE; - } else { - // time to search and find if the endline is inside a comment or not - // start at the first comment, and move forward keeping track of the - // nesting level, if the nest level is 0, i.e. outside a comment - // and we find the ;; return TRUE immediately, otherwise keep searching - // if we end with a nest level >0 return FALSE - - char *c = firstComment+2; // firstComment[0] is the '(', firstComment[1] is the '*' - int nestLevel = 1; // we have a (* - - // in-comment determiner loop - while(c[0] != '\0') - { - // are we an endline - if((c[0] == ';') && (c[1] == ';')) - { - // if we are NOT in a comment, its a full line - if(nestLevel <= 0) - { - free(line); - return TRUE; - } - } - - // are we in a comment? - if((c[0] == '(') && (c[1] == '*')) - { - nestLevel++; - - // watch out we may go past the end - if(c[2] == '\0') - { - free(line); - return FALSE; - } - - // c needs to advance past the *, cause (*) is NOT the start/finish of a comment - c++; - } - - // adjust the nesting down a level - if((c[0] == '*') && (c[1] == ')')) - nestLevel--; - - // next char - c++; - } - - // not a full line - free(line); - return FALSE; - } - } - - // weird case ;) - free(line); - return FALSE; + // if there is a ;; on the line, return true + char *line = editbuffer_getasline(CurrentEditBuffer); + char *firstComment, *firstSemiColonSemiColon, *firstQuote; + + if(line == NULL) + { + return FALSE; + } + + firstComment = strstr(line, "(*"); + firstSemiColonSemiColon = strstr(line, ";;"); + firstQuote = strstr(line, "\""); + + // easy case :D + if(firstSemiColonSemiColon == NULL) + { + free(line); + return FALSE; + } + + // if there are no comments + if(firstComment == NULL) + { + // if there are no quotations used + if(firstQuote == NULL) + { + BOOL r = (firstSemiColonSemiColon != NULL); + free(line); + return r; + } else { + // we need to first check if the ;; is before the \", since the \" + // won't matter if its before the semicolonsemicolon + if(firstQuote < firstSemiColonSemiColon) + { + // the quote is before the ;;, we need to make sure its terminated + // also we have to check for escaped quotes, le sigh! + char *c = firstQuote+1; + BOOL in_quote = TRUE; + + // in-quote determiner loop + while(c[0] != '\0') + { + // are we a backslash? + if(c[0] == '\\') + { + // ignore the next character + c++; + } + else + { + // are we a quote? + if(c[0] == '"') + { + in_quote = !in_quote; + } + } + + c++; + } + + free(line); + return !in_quote; + } else { + BOOL r = (firstSemiColonSemiColon != NULL); + free(line); + return r; + } + } + } else { + // we have to search through finding all comments + + // a neat little trick we can do is compare the point at which + // the ;; is and where the first (* can be found, if the ;; is + // before the (* ocaml.exe ignores the comment + if((unsigned int)firstSemiColonSemiColon < (unsigned int)firstComment) + { + free(line); + return TRUE; + } else { + // time to search and find if the endline is inside a comment or not + // start at the first comment, and move forward keeping track of the + // nesting level, if the nest level is 0, i.e. outside a comment + // and we find the ;; return TRUE immediately, otherwise keep searching + // if we end with a nest level >0 return FALSE + + char *c = firstComment+2; // firstComment[0] is the '(', firstComment[1] is the '*' + int nestLevel = 1; // we have a (* + + // in-comment determiner loop + while(c[0] != '\0') + { + // are we an endline + if((c[0] == ';') && (c[1] == ';')) + { + // if we are NOT in a comment, its a full line + if(nestLevel <= 0) + { + free(line); + return TRUE; + } + } + + // are we in a comment? + if((c[0] == '(') && (c[1] == '*')) + { + nestLevel++; + + // watch out we may go past the end + if(c[2] == '\0') + { + free(line); + return FALSE; + } + + // c needs to advance past the *, cause (*) is NOT the start/finish of a comment + c++; + } + + // adjust the nesting down a level + if((c[0] == '*') && (c[1] == ')')) + nestLevel--; + + // next char + c++; + } + + // not a full line + free(line); + return FALSE; + } + } + + // weird case ;) + free(line); + return FALSE; } /*------------------------------------------------------------------------ Procedure: AppendToEditBuffer ID:1 -Author: Chris Watford watford@uiuc.edu +Author: Chris Watford watford@uiuc.edu Purpose: Add a line to the edit buffer -Input: Handle of the edit control +Input: Handle of the edit control Output: Errors: ------------------------------------------------------------------------*/ void AppendToEditBuffer(HWND hEdit) { - char *p = NULL, linebuffer[2048]; - int n = 0; - int curline = GetCurLineIndex(hEdit); - int linescount = GetNumberOfLines(hEdit); - - // they are passing the size of the buffer as - // the first 'short' in the array... - *(unsigned short *)linebuffer = sizeof(linebuffer)-1; - - if (curline > (linescount-1)) - { - n = SendMessage(hEdit, EM_GETLINE, curline, (LPARAM)linebuffer); - } else { - n = SendMessage(hEdit, EM_GETLINE, --curline, (LPARAM)linebuffer); - } - - // correct for the prompt line - if (n >= 2 && linebuffer[0] == '#' && linebuffer[1] == ' ') - { - n -= 2; - memmove(linebuffer, linebuffer+2, n); - } - - linebuffer[n] = '\0'; - - // linebuffer now has the line to add to our edit buffer - editbuffer_updateoraddline(CurrentEditBuffer, (curline - LastPromptPosition.line), linebuffer); + char *p = NULL, linebuffer[2048]; + int n = 0; + int curline = GetCurLineIndex(hEdit); + int linescount = GetNumberOfLines(hEdit); + + // they are passing the size of the buffer as + // the first 'short' in the array... + *(unsigned short *)linebuffer = sizeof(linebuffer)-1; + + if (curline > (linescount-1)) + { + n = SendMessage(hEdit, EM_GETLINE, curline, (LPARAM)linebuffer); + } else { + n = SendMessage(hEdit, EM_GETLINE, --curline, (LPARAM)linebuffer); + } + + // correct for the prompt line + if (n >= 2 && linebuffer[0] == '#' && linebuffer[1] == ' ') + { + n -= 2; + memmove(linebuffer, linebuffer+2, n); + } + + linebuffer[n] = '\0'; + + // linebuffer now has the line to add to our edit buffer + editbuffer_updateoraddline(CurrentEditBuffer, (curline - LastPromptPosition.line), linebuffer); } /*------------------------------------------------------------------------ @@ -1189,10 +1191,10 @@ Errors: ------------------------------------------------------------------------*/ void SetLastPrompt(HWND hEdit) { - DWORD startpos,endpos; - SendMessage(hEdit,EM_GETSEL,(WPARAM)&startpos,(LPARAM)&endpos); - LastPromptPosition.line = SendMessage(hEdit,EM_LINEFROMCHAR,(WPARAM)-1,0); - LastPromptPosition.col = startpos; + DWORD startpos,endpos; + SendMessage(hEdit,EM_GETSEL,(WPARAM)&startpos,(LPARAM)&endpos); + LastPromptPosition.line = SendMessage(hEdit,EM_LINEFROMCHAR,(WPARAM)-1,0); + LastPromptPosition.col = startpos; } /*------------------------------------------------------------------------ @@ -1206,194 +1208,194 @@ Output: Errors: -------------------------------------------------------------------------- Edit History: - 14 Sept 2003 - Chris Watford watford@uiuc.edu - - Added edit buffer and statement buffer support to the WM_NEWLINE - message. - 15 Sept 2003 - Chris Watford watford@uiuc.edu - - Got it adding to the edit buffer - 16 Sept 2003 - Chris Watford watford@uiuc.edu - - Proper handling of newline message finished - 21 Sept 2003 - Chris Watford watford@uiuc.edu - - Added error detection on return from ocaml interp - 23 Sept 2003 - Chris Watford watford@uiuc.edu - - Fixed prompt detection error as pointed out by Patrick Meredith + 14 Sept 2003 - Chris Watford watford@uiuc.edu + - Added edit buffer and statement buffer support to the WM_NEWLINE + message. + 15 Sept 2003 - Chris Watford watford@uiuc.edu + - Got it adding to the edit buffer + 16 Sept 2003 - Chris Watford watford@uiuc.edu + - Proper handling of newline message finished + 21 Sept 2003 - Chris Watford watford@uiuc.edu + - Added error detection on return from ocaml interp + 23 Sept 2003 - Chris Watford watford@uiuc.edu + - Fixed prompt detection error as pointed out by Patrick Meredith ------------------------------------------------------------------------*/ static LRESULT CALLBACK MdiChildWndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) { - HWND hwndChild; - RECT rc; - HDC hDC; - - switch(msg) { - case WM_CREATE: - GetClientRect(hwnd,&rc); - hwndChild= CreateWindow("EDIT", - NULL, - WS_CHILD | WS_VISIBLE | - ES_MULTILINE | - WS_VSCROLL | WS_HSCROLL | - ES_AUTOHSCROLL | ES_AUTOVSCROLL, - 0, - 0, - (rc.right-rc.left), - (rc.bottom-rc.top), - hwnd, - (HMENU) EditControls++, - hInst, - NULL); - SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) hwndChild); - SendMessage(hwndChild, WM_SETFONT, (WPARAM) ProgramParams.hFont, 0L); - SendMessage(hwndChild,EM_LIMITTEXT,0xffffffff,0); - SubClassEditField(hwndChild); - break; - // Resize the edit control - case WM_SIZE: - hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER); - MoveWindow(hwndChild, 0, 0, LOWORD(lparam), HIWORD(lparam), TRUE); - break; - // Always set the focus to the edit control. - case WM_SETFOCUS: - hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER); - SetFocus(hwndChild); - break; - // Repainting of the edit control about to happen. - // Set the text color and the background color - case WM_CTLCOLOREDIT: - hDC = (HDC)wparam; - SetTextColor(hDC,ProgramParams.TextColor); - SetBkColor(hDC,BackColor); - return (LRESULT)BackgroundBrush; - // Take care of erasing the background color to avoid flicker - case WM_ERASEBKGND: - GetWindowRect(hwnd,&rc); - hDC = (HDC)wparam; - FillRect(hDC,&rc,BackgroundBrush); - return 1; - // A carriage return has been pressed. Send the data to the interpreted. - // This message is posted by the subclassed edit field. - case WM_COMMAND: - if (LOWORD(wparam) >= IDEDITCONTROL && LOWORD(wparam) < IDEDITCONTROL+5) { - switch (HIWORD(wparam)) { - case EN_ERRSPACE: - case EN_MAXTEXT: - ResetText(); - break; - } - } - break; - case WM_NEWLINE: - if (busy) - break; - - hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER); - - // add what they wrote to the edit buffer - AppendToEditBuffer(hwndChild); - - /** Modified by Chris Watford 14 Sept 2003, 15 Sept 2003, 16 Sept 2003 **/ - // test if this line has an end or if it needs to be in the Edit Buffer - if(SendingFullCommand()) - { - // send the edit buffer to the interpreter - //SendLastLine(hwndChild); - SendLastEditBuffer(hwndChild); - historyEntry = NULL; - } else { - AddStringToControl(" "); - } - /** End Modifications **/ - - break; - // The timer will call us 4 times a second. Look if the interpreter - // has written something in its end of the pipe. - case WM_TIMERTICK: - /** Modified by Chris Watford 21 Sept 2003 **/ - hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER); - - if (ReadToLineBuffer()) - { - int errMsg = 0; - char *p, *l = lineBuffer; - - // Ok we read something. Display the trimmed version - while(((*l) == ' ') || ((*l) == '\t') || ((*l) == '\n') || ((*l) == '\r') || ((*l) == '*')) - l++; - - SendMessage(hwndChild,EM_REPLACESEL,0,(LPARAM)l); - - // fix bug where it won't find prompt - p = strrchr(l, '\r'); - if((l[0] == '#') || (p != NULL)) - { - if(p != NULL) - { - if(!strcmp(p, "\r\n# ")) - { - SetLastPrompt(hwndChild); - } - // solve the bug Patrick found - } else if((l[0] == '#') && (l[1] == ' ')) { - SetLastPrompt(hwndChild); - } - } - - // detect syntax errors - if(strstr(lineBuffer, "Syntax error")) - { - errMsg = WM_SYNTAXERROR; - } else if(strstr(lineBuffer, "Illegal character")) { - errMsg = WM_ILLEGALCHAR; - } else if(strstr(lineBuffer, "Unbound value")) { - errMsg = WM_UNBOUNDVAL; - } - - // error! error! alert alert! - if(errMsg > 0) - { - int len = strlen(lineBuffer); - char* err = (char*)SafeMalloc(len+1); - char *m = err, *n1 = NULL, *n2 = NULL, *nt = NULL; - - // make a copy of the message - strncpy(err, lineBuffer, len); - err[len] = '\0'; - - // find it - m = strstr(err, "Characters "); - if(m == NULL) - break; - - // got the start char - n1 = m + strlen("Characters "); - - // start looking for the end char - nt = strstr(n1, "-"); - if(nt == NULL) - break; - - // makes n1 a valid string - nt[0] = '\0'; - - // end char is right after this - n2 = nt + 1; - - // find the end of n2 - nt = strstr(n2, ":"); - if(nt == NULL) - break; - - // makes n2 a valid string - nt[0] = '\0'; - - SendMessage(hwndChild, errMsg, (WPARAM)atoi(n1), (LPARAM)atoi(n2)); - } - } - /** End Modifications **/ - - break; - - } - return DefMDIChildProc(hwnd, msg, wparam, lparam); + HWND hwndChild; + RECT rc; + HDC hDC; + + switch(msg) { + case WM_CREATE: + GetClientRect(hwnd,&rc); + hwndChild= CreateWindow("EDIT", + NULL, + WS_CHILD | WS_VISIBLE | + ES_MULTILINE | + WS_VSCROLL | WS_HSCROLL | + ES_AUTOHSCROLL | ES_AUTOVSCROLL, + 0, + 0, + (rc.right-rc.left), + (rc.bottom-rc.top), + hwnd, + (HMENU) EditControls++, + hInst, + NULL); + SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) hwndChild); + SendMessage(hwndChild, WM_SETFONT, (WPARAM) ProgramParams.hFont, 0L); + SendMessage(hwndChild,EM_LIMITTEXT,0xffffffff,0); + SubClassEditField(hwndChild); + break; + // Resize the edit control + case WM_SIZE: + hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER); + MoveWindow(hwndChild, 0, 0, LOWORD(lparam), HIWORD(lparam), TRUE); + break; + // Always set the focus to the edit control. + case WM_SETFOCUS: + hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER); + SetFocus(hwndChild); + break; + // Repainting of the edit control about to happen. + // Set the text color and the background color + case WM_CTLCOLOREDIT: + hDC = (HDC)wparam; + SetTextColor(hDC,ProgramParams.TextColor); + SetBkColor(hDC,BackColor); + return (LRESULT)BackgroundBrush; + // Take care of erasing the background color to avoid flicker + case WM_ERASEBKGND: + GetWindowRect(hwnd,&rc); + hDC = (HDC)wparam; + FillRect(hDC,&rc,BackgroundBrush); + return 1; + // A carriage return has been pressed. Send the data to the interpreted. + // This message is posted by the subclassed edit field. + case WM_COMMAND: + if (LOWORD(wparam) >= IDEDITCONTROL && LOWORD(wparam) < IDEDITCONTROL+5) { + switch (HIWORD(wparam)) { + case EN_ERRSPACE: + case EN_MAXTEXT: + ResetText(); + break; + } + } + break; + case WM_NEWLINE: + if (busy) + break; + + hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER); + + // add what they wrote to the edit buffer + AppendToEditBuffer(hwndChild); + + /** Modified by Chris Watford 14 Sept 2003, 15 Sept 2003, 16 Sept 2003 **/ + // test if this line has an end or if it needs to be in the Edit Buffer + if(SendingFullCommand()) + { + // send the edit buffer to the interpreter + //SendLastLine(hwndChild); + SendLastEditBuffer(hwndChild); + historyEntry = NULL; + } else { + AddStringToControl(" "); + } + /** End Modifications **/ + + break; + // The timer will call us 4 times a second. Look if the interpreter + // has written something in its end of the pipe. + case WM_TIMERTICK: + /** Modified by Chris Watford 21 Sept 2003 **/ + hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER); + + if (ReadToLineBuffer()) + { + int errMsg = 0; + char *p, *l = lineBuffer; + + // Ok we read something. Display the trimmed version + while(((*l) == ' ') || ((*l) == '\t') || ((*l) == '\n') || ((*l) == '\r') || ((*l) == '*')) + l++; + + SendMessage(hwndChild,EM_REPLACESEL,0,(LPARAM)l); + + // fix bug where it won't find prompt + p = strrchr(l, '\r'); + if((l[0] == '#') || (p != NULL)) + { + if(p != NULL) + { + if(!strcmp(p, "\r\n# ")) + { + SetLastPrompt(hwndChild); + } + // solve the bug Patrick found + } else if((l[0] == '#') && (l[1] == ' ')) { + SetLastPrompt(hwndChild); + } + } + + // detect syntax errors + if(strstr(lineBuffer, "Syntax error")) + { + errMsg = WM_SYNTAXERROR; + } else if(strstr(lineBuffer, "Illegal character")) { + errMsg = WM_ILLEGALCHAR; + } else if(strstr(lineBuffer, "Unbound value")) { + errMsg = WM_UNBOUNDVAL; + } + + // error! error! alert alert! + if(errMsg > 0) + { + int len = strlen(lineBuffer); + char* err = (char*)SafeMalloc(len+1); + char *m = err, *n1 = NULL, *n2 = NULL, *nt = NULL; + + // make a copy of the message + strncpy(err, lineBuffer, len); + err[len] = '\0'; + + // find it + m = strstr(err, "Characters "); + if(m == NULL) + break; + + // got the start char + n1 = m + strlen("Characters "); + + // start looking for the end char + nt = strstr(n1, "-"); + if(nt == NULL) + break; + + // makes n1 a valid string + nt[0] = '\0'; + + // end char is right after this + n2 = nt + 1; + + // find the end of n2 + nt = strstr(n2, ":"); + if(nt == NULL) + break; + + // makes n2 a valid string + nt[0] = '\0'; + + SendMessage(hwndChild, errMsg, (WPARAM)atoi(n1), (LPARAM)atoi(n2)); + } + } + /** End Modifications **/ + + break; + + } + return DefMDIChildProc(hwnd, msg, wparam, lparam); } @@ -1413,52 +1415,52 @@ Errors: ------------------------------------------------------------------------*/ static LRESULT CALLBACK MainWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) { - switch (msg) { - // Create the MDI client invisible window - case WM_CREATE: - hwndMDIClient = CreateMdiClient(hwnd); - TimerId = SetTimer((HWND) 0, 0, 100, (TIMERPROC) TimerProc); - break; - // Move the child windows - case WM_SIZE: - SendMessage(hWndStatusbar,msg,wParam,lParam); - InitializeStatusBar(hWndStatusbar,1); - // Position the MDI client window between the tool and status bars - if (wParam != SIZE_MINIMIZED) { - RECT rc, rcClient; - - GetClientRect(hwnd, &rcClient); - GetWindowRect(hWndStatusbar, &rc); - ScreenToClient(hwnd, (LPPOINT)&rc.left); - rcClient.bottom = rc.top; - MoveWindow(hwndMDIClient,rcClient.left,rcClient.top,rcClient.right-rcClient.left, rcClient.bottom-rcClient.top, TRUE); - } - - return 0; - // Dispatch the menu commands - case WM_COMMAND: - HandleCommand(hwnd, wParam,lParam); - return 0; - // If user confirms close - case WM_CLOSE: - if (!AskYesOrNo("Quit OCamlWinPlus?")) - return 0; - break; - // End application - case WM_DESTROY: - PostQuitMessage(0); - break; - // The interpreter has exited. Force close of the application - case WM_QUITOCAML: - DestroyWindow(hwnd); - return 0; - case WM_USER+1000: - // TestGraphics(); - break; - default: - return DefFrameProc(hwnd,hwndMDIClient,msg,wParam,lParam); - } - return DefFrameProc(hwnd,hwndMDIClient,msg,wParam,lParam); + switch (msg) { + // Create the MDI client invisible window + case WM_CREATE: + hwndMDIClient = CreateMdiClient(hwnd); + TimerId = SetTimer((HWND) 0, 0, 100, (TIMERPROC) TimerProc); + break; + // Move the child windows + case WM_SIZE: + SendMessage(hWndStatusbar,msg,wParam,lParam); + InitializeStatusBar(hWndStatusbar,1); + // Position the MDI client window between the tool and status bars + if (wParam != SIZE_MINIMIZED) { + RECT rc, rcClient; + + GetClientRect(hwnd, &rcClient); + GetWindowRect(hWndStatusbar, &rc); + ScreenToClient(hwnd, (LPPOINT)&rc.left); + rcClient.bottom = rc.top; + MoveWindow(hwndMDIClient,rcClient.left,rcClient.top,rcClient.right-rcClient.left, rcClient.bottom-rcClient.top, TRUE); + } + + return 0; + // Dispatch the menu commands + case WM_COMMAND: + HandleCommand(hwnd, wParam,lParam); + return 0; + // If user confirms close + case WM_CLOSE: + if (!AskYesOrNo("Quit OCamlWinPlus?")) + return 0; + break; + // End application + case WM_DESTROY: + PostQuitMessage(0); + break; + // The interpreter has exited. Force close of the application + case WM_QUITOCAML: + DestroyWindow(hwnd); + return 0; + case WM_USER+1000: + // TestGraphics(); + break; + default: + return DefFrameProc(hwnd,hwndMDIClient,msg,wParam,lParam); + } + return DefFrameProc(hwnd,hwndMDIClient,msg,wParam,lParam); } /*------------------------------------------------------------------------ @@ -1470,17 +1472,17 @@ Errors: ------------------------------------------------------------------------*/ static HFONT CreationCourier(int flag) { - LOGFONT CurrentFont; - memset(&CurrentFont, 0, sizeof(LOGFONT)); - CurrentFont.lfCharSet = ANSI_CHARSET; - CurrentFont.lfWeight = FW_NORMAL; - if (flag) - CurrentFont.lfHeight = 18; - else - CurrentFont.lfHeight = 15; - CurrentFont.lfPitchAndFamily = (BYTE) (FIXED_PITCH | FF_MODERN); - strcpy(CurrentFont.lfFaceName, "Courier"); /* Courier */ - return (CreateFontIndirect(&CurrentFont)); + LOGFONT CurrentFont; + memset(&CurrentFont, 0, sizeof(LOGFONT)); + CurrentFont.lfCharSet = ANSI_CHARSET; + CurrentFont.lfWeight = FW_NORMAL; + if (flag) + CurrentFont.lfHeight = 18; + else + CurrentFont.lfHeight = 15; + CurrentFont.lfPitchAndFamily = (BYTE) (FIXED_PITCH | FF_MODERN); + strcpy(CurrentFont.lfFaceName, "Courier"); /* Courier */ + return (CreateFontIndirect(&CurrentFont)); } /*------------------------------------------------------------------------ @@ -1493,8 +1495,8 @@ Errors: None ------------------------------------------------------------------------*/ int ReadToLineBuffer(void) { - memset(lineBuffer,0,sizeof(lineBuffer)); - return ReadFromPipe(lineBuffer,sizeof(lineBuffer)); + memset(lineBuffer,0,sizeof(lineBuffer)); + return ReadFromPipe(lineBuffer,sizeof(lineBuffer)); } /*------------------------------------------------------------------------ @@ -1507,10 +1509,10 @@ Errors: ------------------------------------------------------------------------*/ int AddLineBuffer(void) { - HWND hEditCtrl; + HWND hEditCtrl; - hEditCtrl = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); - return SendMessage(hEditCtrl,EM_REPLACESEL,0,(LPARAM)lineBuffer); + hEditCtrl = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + return SendMessage(hEditCtrl,EM_REPLACESEL,0,(LPARAM)lineBuffer); } @@ -1524,14 +1526,14 @@ Errors: ------------------------------------------------------------------------*/ static int Setup(HANDLE *phAccelTable) { - if (!InitApplication()) - return 0; - ProgramParams.hFont = CreationCourier(1); - ProgramParams.TextColor = RGB(0,0,0); - GetObject(ProgramParams.hFont,sizeof(LOGFONT),&CurrentFont); - BackgroundBrush = CreateSolidBrush(BackColor); - *phAccelTable = LoadAccelerators(hInst,MAKEINTRESOURCE(IDACCEL)); - return 1; + if (!InitApplication()) + return 0; + ProgramParams.hFont = CreationCourier(1); + ProgramParams.TextColor = RGB(0,0,0); + GetObject(ProgramParams.hFont,sizeof(LOGFONT),&CurrentFont); + BackgroundBrush = CreateSolidBrush(BackColor); + *phAccelTable = LoadAccelerators(hInst,MAKEINTRESOURCE(IDACCEL)); + return 1; } @@ -1544,56 +1546,56 @@ Errors: ------------------------------------------------------------------------*/ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow) { - MSG msg; - HANDLE hAccelTable; - char consoleTitle[512]; - HWND hwndConsole; - - CurrentEditBuffer = (EditBuffer*)SafeMalloc(sizeof(EditBuffer)); - CurrentEditBuffer->LineCount = 0; - CurrentEditBuffer->Lines = NULL; - - //setup the history index pointer - historyEntry = NULL; - - // Setup the hInst global - hInst = hInstance; - // Do the setup - if (!Setup(&hAccelTable)) - return 0; - // Need to set up a console so that we can send ctrl-break signal - // to inferior Caml - AllocConsole(); - GetConsoleTitle(consoleTitle,sizeof(consoleTitle)); - hwndConsole = FindWindow(NULL,consoleTitle); - ShowWindow(hwndConsole,SW_HIDE); - // Create main window and exit if this fails - if ((hwndMain = CreateinriaWndClassWnd()) == (HWND)0) - return 0; - // Create the status bar - CreateSBar(hwndMain,"Ready",2); - // Show the window - ShowWindow(hwndMain,SW_SHOW); - // Create the session window - hwndSession = MDICmdFileNew("Session transcript",0); - // Get the path to ocaml.exe - GetOcamlPath(); - // Start the interpreter - StartOcaml(); - // Show the session window - ShowWindow(hwndSession, SW_SHOW); - // Maximize it - SendMessage(hwndMDIClient, WM_MDIMAXIMIZE, (WPARAM) hwndSession, 0); - - PostMessage(hwndMain,WM_USER+1000,0,0); - while (GetMessage(&msg,NULL,0,0)) { - if (!TranslateMDISysAccel(hwndMDIClient, &msg)) - if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { - TranslateMessage(&msg); // Translates virtual key codes - DispatchMessage(&msg); // Dispatches message to window - } - } - WriteToPipe("#quit;;\r\n\032"); - KillTimer((HWND) 0, TimerId); - return msg.wParam; + MSG msg; + HANDLE hAccelTable; + char consoleTitle[512]; + HWND hwndConsole; + + CurrentEditBuffer = (EditBuffer*)SafeMalloc(sizeof(EditBuffer)); + CurrentEditBuffer->LineCount = 0; + CurrentEditBuffer->Lines = NULL; + + //setup the history index pointer + historyEntry = NULL; + + // Setup the hInst global + hInst = hInstance; + // Do the setup + if (!Setup(&hAccelTable)) + return 0; + // Need to set up a console so that we can send ctrl-break signal + // to inferior Caml + AllocConsole(); + GetConsoleTitle(consoleTitle,sizeof(consoleTitle)); + hwndConsole = FindWindow(NULL,consoleTitle); + ShowWindow(hwndConsole,SW_HIDE); + // Create main window and exit if this fails + if ((hwndMain = CreateinriaWndClassWnd()) == (HWND)0) + return 0; + // Create the status bar + CreateSBar(hwndMain,"Ready",2); + // Show the window + ShowWindow(hwndMain,SW_SHOW); + // Create the session window + hwndSession = MDICmdFileNew("Session transcript",0); + // Get the path to ocaml.exe + GetOcamlPath(); + // Start the interpreter + StartOcaml(); + // Show the session window + ShowWindow(hwndSession, SW_SHOW); + // Maximize it + SendMessage(hwndMDIClient, WM_MDIMAXIMIZE, (WPARAM) hwndSession, 0); + + PostMessage(hwndMain,WM_USER+1000,0,0); + while (GetMessage(&msg,NULL,0,0)) { + if (!TranslateMDISysAccel(hwndMDIClient, &msg)) + if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { + TranslateMessage(&msg); // Translates virtual key codes + DispatchMessage(&msg); // Dispatches message to window + } + } + WriteToPipe("#quit;;\r\n\032"); + KillTimer((HWND) 0, TimerId); + return msg.wParam; } diff --git a/win32caml/ocaml.rc b/win32caml/ocaml.rc index 52ae94974..0aab9c3c7 100644 --- a/win32caml/ocaml.rc +++ b/win32caml/ocaml.rc @@ -106,7 +106,7 @@ EXSTYLE WS_EX_TOOLWINDOW | WS_EX_CLIENTEDGE CAPTION "About OCamlWinPlus" FONT 8, "MS Sans Serif", 0, 0, 0x1 BEGIN - LTEXT "Objective Caml for Windows",101,75,7,90,12 + LTEXT "OCaml for Windows",101,75,7,90,12 LTEXT "New Windows Interface 1.9RC4",102,68,15,104,12 CTEXT "Copyright 1996-2001\nUpdated 2003",103,88,25,66,23 CTEXT "Institut National de Recherche en Informatique et Automatique", diff --git a/win32caml/startocaml.c b/win32caml/startocaml.c index f1a3562d9..d457dd41b 100644 --- a/win32caml/startocaml.c +++ b/win32caml/startocaml.c @@ -1,8 +1,9 @@ /***********************************************************************/ /* */ -/* Objective Caml */ +/* OCaml */ /* */ /* Developed by Jacob Navia. */ +/* */ /* Copyright 2001 Institut National de Recherche en Informatique et */ /* en Automatique. All rights reserved. This file is distributed */ /* under the terms of the GNU Library General Public License, with */ @@ -37,28 +38,28 @@ Errors: ------------------------------------------------------------------------*/ void ShowDbgMsg(char *str) { - HWND hWnd; - char p[20], message[255]; - hWnd = hwndMain; - if (IsIconic(hWnd)){ - ShowWindow(hWnd,SW_RESTORE); - } - strncpy(message, str, 254); - message[254] = 0; - strcpy(p, "Error"); - MessageBox(hWnd, message, p, MB_OK | MB_ICONHAND|MB_TASKMODAL|MB_SETFOREGROUND); + HWND hWnd; + char p[20], message[255]; + hWnd = hwndMain; + if (IsIconic(hWnd)){ + ShowWindow(hWnd,SW_RESTORE); + } + strncpy(message, str, 254); + message[254] = 0; + strcpy(p, "Error"); + MessageBox(hWnd, message, p, MB_OK | MB_ICONHAND|MB_TASKMODAL|MB_SETFOREGROUND); } int AskYesOrNo(char *msg) { - HWND hwnd; - int r; - - hwnd = hwndMain; - r = MessageBox(hwnd, msg, "Ocaml", MB_YESNO | MB_SETFOREGROUND); - if (r == IDYES) - return (TRUE); - return (FALSE); + HWND hwnd; + int r; + + hwnd = hwndMain; + r = MessageBox(hwnd, msg, "Ocaml", MB_YESNO | MB_SETFOREGROUND); + if (r == IDYES) + return (TRUE); + return (FALSE); } @@ -66,60 +67,60 @@ static DWORD OcamlStatus; static int RegistryError(void) { - char buf[512]; + char buf[512]; - wsprintf(buf,"Error %d writing to the registry",GetLastError()); - ShowDbgMsg(buf); - return 0; + wsprintf(buf,"Error %d writing to the registry",GetLastError()); + ShowDbgMsg(buf); + return 0; } static int ReadRegistry(HKEY hroot, - char * p1, char * p2, char * p3, - char dest[1024]) + char * p1, char * p2, char * p3, + char dest[1024]) { - HKEY h1, h2; - DWORD dwType; - unsigned long size; - LONG ret; - - if (RegOpenKeyExA(hroot, p1, 0, KEY_QUERY_VALUE, &h1) != ERROR_SUCCESS) - return 0; - if (RegOpenKeyExA(h1, p2, 0, KEY_QUERY_VALUE, &h2) != ERROR_SUCCESS) { - RegCloseKey(h1); - return 0; - } - dwType = REG_SZ; - size = 1024; - ret = RegQueryValueExA(h2, p3, 0, &dwType, dest, &size); - RegCloseKey(h2); - RegCloseKey(h1); - return ret == ERROR_SUCCESS; + HKEY h1, h2; + DWORD dwType; + unsigned long size; + LONG ret; + + if (RegOpenKeyExA(hroot, p1, 0, KEY_QUERY_VALUE, &h1) != ERROR_SUCCESS) + return 0; + if (RegOpenKeyExA(h1, p2, 0, KEY_QUERY_VALUE, &h2) != ERROR_SUCCESS) { + RegCloseKey(h1); + return 0; + } + dwType = REG_SZ; + size = 1024; + ret = RegQueryValueExA(h2, p3, 0, &dwType, dest, &size); + RegCloseKey(h2); + RegCloseKey(h1); + return ret == ERROR_SUCCESS; } static int WriteRegistry(HKEY hroot, - char * p1, char * p2, char * p3, - char data[1024]) + char * p1, char * p2, char * p3, + char data[1024]) { - HKEY h1, h2; - DWORD disp; - LONG ret; - - if (RegOpenKeyExA(hroot, p1, 0, KEY_QUERY_VALUE, &h1) != ERROR_SUCCESS) - return 0; - if (RegCreateKeyExA(h1, p2, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &h2, &disp) - != ERROR_SUCCESS) { - RegCloseKey(h1); - return 0; - } - ret = RegSetValueEx(h2, p3, 0, REG_SZ, data, strlen(data) + 1); - RegCloseKey(h2); - RegCloseKey(h1); - return ret == ERROR_SUCCESS; + HKEY h1, h2; + DWORD disp; + LONG ret; + + if (RegOpenKeyExA(hroot, p1, 0, KEY_QUERY_VALUE, &h1) != ERROR_SUCCESS) + return 0; + if (RegCreateKeyExA(h1, p2, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &h2, &disp) + != ERROR_SUCCESS) { + RegCloseKey(h1); + return 0; + } + ret = RegSetValueEx(h2, p3, 0, REG_SZ, data, strlen(data) + 1); + RegCloseKey(h2); + RegCloseKey(h1); + return ret == ERROR_SUCCESS; } /*------------------------------------------------------------------------ Procedure: GetOcamlPath ID:1 -Purpose: Read the registry key +Purpose: Read the registry key HKEY_LOCAL_MACHINE\Software\Objective Caml or HKEY_CURRENT_USER\Software\Objective Caml, @@ -141,13 +142,13 @@ int GetOcamlPath(void) char path[1024], *p; while (( !ReadRegistry(HKEY_CURRENT_USER, - "Software", "Objective Caml", - "InterpreterPath", path) - && - !ReadRegistry(HKEY_LOCAL_MACHINE, - "Software", "Objective Caml", - "InterpreterPath", path)) - || _access(path, 0) != 0) { + "Software", "Objective Caml", + "InterpreterPath", path) + && + !ReadRegistry(HKEY_LOCAL_MACHINE, + "Software", "Objective Caml", + "InterpreterPath", path)) + || _access(path, 0) != 0) { /* Registry key doesn't exist or contains invalid path */ /* Ask user */ if (!BrowseForFile("Ocaml interpreter|ocaml.exe", path)) { @@ -155,8 +156,8 @@ int GetOcamlPath(void) exit(0); } WriteRegistry(HKEY_CURRENT_USER, - "Software", "Objective Caml", - "InterpreterPath", path); + "Software", "Objective Caml", + "InterpreterPath", path); /* Iterate to validate again */ } strcpy(OcamlPath, path); @@ -185,11 +186,11 @@ Errors: ------------------------------------------------------------------------*/ int IsWindowsNT(void) { - OSVERSIONINFO osv; + OSVERSIONINFO osv; - osv.dwOSVersionInfoSize = sizeof(osv); - GetVersionEx(&osv); - return(osv.dwPlatformId == VER_PLATFORM_WIN32_NT); + osv.dwOSVersionInfoSize = sizeof(osv); + GetVersionEx(&osv); + return(osv.dwPlatformId == VER_PLATFORM_WIN32_NT); } /*------------------------------------------------------------------------ @@ -215,56 +216,56 @@ thread will exit. No error message is shown. DWORD WINAPI DoStartOcaml(LPVOID param) { HWND hwndParent = (HWND) param; - char *cmdline; - int processStarted; - LPSECURITY_ATTRIBUTES lpsa=NULL; - SECURITY_ATTRIBUTES sa; - SECURITY_DESCRIPTOR sd; - - sa.nLength = sizeof(SECURITY_ATTRIBUTES); - // Under windows NT/2000/Whistler we have to initialize the security descriptors - // This is not necessary under windows 98/95. - if (IsWindowsNT()) { - InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION); - SetSecurityDescriptorDacl(&sd,TRUE,NULL,FALSE); - sa.bInheritHandle = TRUE; - sa.lpSecurityDescriptor = &sd; - lpsa = &sa; - } - memset(&startInfo,0,sizeof(STARTUPINFO)); - startInfo.cb = sizeof(STARTUPINFO); - // Create a pipe for the child process's STDOUT. - if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &sa, 0)) - return 0; - // Create a pipe for the child process's STDIN. - if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &sa, 0)) - return 0; - // Setup the start info structure - startInfo.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; - startInfo.wShowWindow = SW_HIDE; - startInfo.hStdOutput = hChildStdoutWr; - startInfo.hStdError = hChildStdoutWr; - startInfo.hStdInput = hChildStdinRd; - cmdline = OcamlPath; - // Set the OCAMLLIB environment variable - SetEnvironmentVariable("OCAMLLIB", LibDir); - // Let's go: start the ocaml interpreter - processStarted = CreateProcess(NULL,cmdline,lpsa,lpsa,1, - CREATE_NEW_PROCESS_GROUP|NORMAL_PRIORITY_CLASS, - NULL,ProgramParams.CurrentWorkingDir,&startInfo,&pi); - if (processStarted) { - WaitForSingleObject(pi.hProcess,INFINITE); - GetExitCodeProcess(pi.hProcess,(unsigned long *)&OcamlStatus); - CloseHandle(pi.hProcess); - PostMessage(hwndMain,WM_QUITOCAML,0,0); - } - else { - char *msg = malloc(1024); - wsprintf(msg,"Impossible to start ocaml.exe in:\n%s",cmdline); - ShowDbgMsg(msg); - free(msg); - } - return 0; + char *cmdline; + int processStarted; + LPSECURITY_ATTRIBUTES lpsa=NULL; + SECURITY_ATTRIBUTES sa; + SECURITY_DESCRIPTOR sd; + + sa.nLength = sizeof(SECURITY_ATTRIBUTES); + // Under windows NT/2000/Whistler we have to initialize the security descriptors + // This is not necessary under windows 98/95. + if (IsWindowsNT()) { + InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION); + SetSecurityDescriptorDacl(&sd,TRUE,NULL,FALSE); + sa.bInheritHandle = TRUE; + sa.lpSecurityDescriptor = &sd; + lpsa = &sa; + } + memset(&startInfo,0,sizeof(STARTUPINFO)); + startInfo.cb = sizeof(STARTUPINFO); + // Create a pipe for the child process's STDOUT. + if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &sa, 0)) + return 0; + // Create a pipe for the child process's STDIN. + if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &sa, 0)) + return 0; + // Setup the start info structure + startInfo.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; + startInfo.wShowWindow = SW_HIDE; + startInfo.hStdOutput = hChildStdoutWr; + startInfo.hStdError = hChildStdoutWr; + startInfo.hStdInput = hChildStdinRd; + cmdline = OcamlPath; + // Set the OCAMLLIB environment variable + SetEnvironmentVariable("OCAMLLIB", LibDir); + // Let's go: start the ocaml interpreter + processStarted = CreateProcess(NULL,cmdline,lpsa,lpsa,1, + CREATE_NEW_PROCESS_GROUP|NORMAL_PRIORITY_CLASS, + NULL,ProgramParams.CurrentWorkingDir,&startInfo,&pi); + if (processStarted) { + WaitForSingleObject(pi.hProcess,INFINITE); + GetExitCodeProcess(pi.hProcess,(unsigned long *)&OcamlStatus); + CloseHandle(pi.hProcess); + PostMessage(hwndMain,WM_QUITOCAML,0,0); + } + else { + char *msg = malloc(1024); + wsprintf(msg,"Impossible to start ocaml.exe in:\n%s",cmdline); + ShowDbgMsg(msg); + free(msg); + } + return 0; } /*------------------------------------------------------------------------ @@ -278,12 +279,12 @@ Errors: None ------------------------------------------------------------------------*/ int WriteToPipe(char *data) { - DWORD dwWritten; + DWORD dwWritten; - if (! WriteFile(hChildStdinWr, data, strlen(data), &dwWritten, NULL)) - return 0; + if (! WriteFile(hChildStdinWr, data, strlen(data), &dwWritten, NULL)) + return 0; - return dwWritten; + return dwWritten; } @@ -300,17 +301,17 @@ Errors: None explicit ------------------------------------------------------------------------*/ int ReadFromPipe(char *data,int len) { - DWORD dwRead; + DWORD dwRead; - PeekNamedPipe(hChildStdoutRd,data,len,NULL,&dwRead,NULL); - if (dwRead == 0) - return 0; + PeekNamedPipe(hChildStdoutRd,data,len,NULL,&dwRead,NULL); + if (dwRead == 0) + return 0; - // Read output from the child process, and write to parent's STDOUT. - if( !ReadFile( hChildStdoutRd, data, len, &dwRead, NULL) || dwRead == 0) - return 0; + // Read output from the child process, and write to parent's STDOUT. + if( !ReadFile( hChildStdoutRd, data, len, &dwRead, NULL) || dwRead == 0) + return 0; - return dwRead; + return dwRead; } static DWORD tid; @@ -324,39 +325,39 @@ Errors: ------------------------------------------------------------------------*/ int StartOcaml(void) { - getcwd(ProgramParams.CurrentWorkingDir,sizeof(ProgramParams.CurrentWorkingDir)); - CreateThread(NULL,0,DoStartOcaml,hwndMain,0,&tid); - return 1; + getcwd(ProgramParams.CurrentWorkingDir,sizeof(ProgramParams.CurrentWorkingDir)); + CreateThread(NULL,0,DoStartOcaml,hwndMain,0,&tid); + return 1; } void *SafeMalloc(int size) { - void *result; + void *result; - if (size < 0) { - char message[1024]; + if (size < 0) { + char message[1024]; error: - sprintf(message,"Can't allocate %d bytes",size); - MessageBox(NULL, message, "Ocaml", MB_OK); - exit(-1); - } - result = malloc(size); + sprintf(message,"Can't allocate %d bytes",size); + MessageBox(NULL, message, "Ocaml", MB_OK); + exit(-1); + } + result = malloc(size); - if (result == NULL) - goto error; + if (result == NULL) + goto error; - return result; + return result; } void InterruptOcaml(void) { - if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pi.dwProcessId)) { - char message[1024]; - sprintf(message, "GenerateConsole failed: %lu\n", GetLastError()); - MessageBox(NULL, message, "Ocaml", MB_OK); - } - WriteToPipe(" "); + if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pi.dwProcessId)) { + char message[1024]; + sprintf(message, "GenerateConsole failed: %lu\n", GetLastError()); + MessageBox(NULL, message, "Ocaml", MB_OK); + } + WriteToPipe(" "); } |