示例#1
0
/*------------------------------------------------------------------------
 Procedure:     SaveML ID:1
 Author:        Chris Watford [email protected]
 Purpose:       Saves the ML source to a file, commenting out functions
                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
                error box
------------------------------------------------------------------------*/
static void SaveML(char *fname)
{
        FILE *f;
        char *buf = SafeMalloc(8192);

        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");
            }
        }

        fclose(f);
        free(buf);
}
示例#2
0
/*------------------------------------------------------------------------
Procedure:     SendLastEditBuffer ID:1
Author:		   Chris Watford [email protected]
Purpose:       Sends an edit buffer to the pipe
Input:
Output:
Errors:
--------------------------------------------------------------------------
Edit History:
     7 Aug  2004 - Chris Watford [email protected]
		- 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 [email protected]
		- 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);
}