Sindbad~EG File Manager

Current Path : /usr/home/beeson/MathXpert/automode/
Upload File :
Current File : /usr/home/beeson/MathXpert/automode/errbuf.c

/* M. Beeson for Mathpert
10.31.95
last modified 7.23.98
1.25.06 made comment_buffer and error_buffer static 
3.17.06 removed include heap.h 
9.8.11  cast result of strlen to int  for 64-bit compilation without warnings
*/

#include <string.h>

#include "heap.h"
#include "heaps.h"
#include "terms.h"
#include "parser.h"
#include "pcontrol.h"
#include "defns.h"  // needed by vaux
#include "vaux.h"   // vardata
#include "proverdl.h"
#include "model.h"
#include "arith.h"
#include "polyval.h"
#include "graphstr.h"
#include "probtype.h"
#include "mpdoc.h"
#include "errbuf.h"
#include "activedoc.h"

/*______________________________________________________________________*/
static int stopflag;


/* The following functions enable access to these buffers by operations
which need to leave error messages or comments */

void errbuf(int i, const char *msg)
   { PDOCDATA pDocData = GetActiveDoc();
     if(!stopflag)
         strncpy(pDocData->papyrus->error_buffer[i],msg,ERRBUFLENGTH);
   }

void commentbuf(int i, const char *msg)
   { PDOCDATA pDocData = GetActiveDoc();
     if(!stopflag)
         strncpy(pDocData->papyrus->comment_buffer[i],msg,COMMENTBUFLENGTH);
   }

/*_________________________________________________________________*/
/* To turn off the comment/error mechanisms temporarily */
int GetCommentStop(void)
   { return stopflag;
   }
void SetCommentStop(int n)
// nonzero prevents comments and errors being put in the document.
//  It should be set during think_ahead
   { stopflag = n;
   }

/*_________________________________________________________________*/
char * get_error_buffer(int i)
{ PDOCDATA pDocData = GetActiveDoc();
  if(i < DIM_ERROR_BUFFER)
     return pDocData->papyrus->error_buffer[i];
  return "";
}
/*_________________________________________________________________*/
void clear_error_buffer(void)
{ PDOCDATA pDocData = GetActiveDoc();
  memset(pDocData->papyrus->error_buffer, 0, ERRBUFLENGTH *DIM_COMMENT_BUFFER);
}
/*_________________________________________________________________*/
char * get_comment_buffer(int i)
{ PDOCDATA pDocData = GetActiveDoc();
  if(i < DIM_COMMENT_BUFFER)
     return (char *) pDocData->papyrus->comment_buffer[i];
  return "";
}
/*_________________________________________________________________*/
void clear_comment_buffer(void)
{ PDOCDATA pDocData = GetActiveDoc();
  memset(pDocData->papyrus->comment_buffer, 0, ERRBUFLENGTH *DIM_COMMENT_BUFFER);
}
/*_________________________________________________________________*/
unsigned char *get_permanent_comment(void)
/* produce a copy on the document heap of
the comment in comment_buffer, if it begins with an
exclamation point (used to indicate it should become part
of the solution rather than a temporary message).
Return NULL if there is no such comment.
*/
{ int i,n;
  unsigned char *ans;
  PDOCDATA pDocData = GetActiveDoc();
  char buf[(ERRBUFLENGTH + 1) * DIM_COMMENT_BUFFER];
  if(pDocData->papyrus->comment_buffer[0][0] != '!')
     return NULL;
  strcpy(buf,pDocData->papyrus->comment_buffer[0]+1);
  for(i=1;i<DIM_COMMENT_BUFFER; i++)
     { if(pDocData->papyrus->comment_buffer[i][0] == '\0')
          break;
       strcat(buf, " ");
       strncat(buf,pDocData->papyrus->comment_buffer[i],ERRBUFLENGTH);
     }
  n = (int) strlen(buf)+1;
  ans = callocate(n, sizeof(char));
  strcpy((char *)ans, buf);
  return ans;
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists