
#include "messages.h"
#include <stream.h>

// The welcome message should be 20 lines or less so that the
// entire initial screen is 25 lines or less.
// (It is not neccessary to end with a new line.)

// pshuang: updated Help/Welcome.txt to contain what the file
// /mit/mitlibs/info/welcome.barton contains as of 6-19-91

char *default_welcome_message =
#include "Help/welcome.barton"
;

char *welcome_message = default_welcome_message;

char* general_help_message =
#include "Help/Emma.txt"
;

/* pshuang: removing, never used... superseded by Barton_help_message
char* barton_help_message =
#include "Help/Barton.txt"
;
*/

// ----------------------------
// -  Random other messages
// -

char *redialing_message = "<Repeating contact attempt...>\n";
	  
char *library_closed_message =
  "Type \\q<RETURN> to quit, or \\\\<RETURN> to continue.\n";

char *cant_refresh_message =
/* pshuang: changed text
  "Unable to automatically refresh screen.
You might try typing <RETURN> or a command.
";
*/
"\nCurrent library is unable to refresh
the screen.  You could try issuing a command
to it or hit <ENTER> a few times.
";

char* system_bug_encountered_message =
"Sorry.  A bug just occured in this program.
Perhaps you might try again in a little while.";

/* pshuang: generalized function to below
int update_messages()
{
    istream in_file("/mit/mitlibs/info/welcome.barton", "r");
    char temp_char = NULL;
    char *buffer = NULL;
    int i = 0;

    if (in_file.is_open()) {
	while(!in_file.eof() &&
	      in_file.get(temp_char)) {
	    if (buffer == NULL) buffer = malloc(1);
	    else buffer = realloc(buffer, i + 1);

	    buffer[i] = temp_char;
	    i += 1;
	}
    }

    if (buffer != NULL) {
	buffer = realloc(buffer, i + 1);
	buffer[i] = 0;
	welcome_message = buffer;
    }
};
*/

char* update_message(char* filename, char* string_to_update)
{
  istream in_file(filename, "r");
  char temp_char = NULL;
  char* buffer = NULL;
  int i = 0;
  
  // This routine seems kind of inefficient (loading one character at a time)
  // but since it only gets run at initialization, not worth changing; also
  // istream.h doesn't seem to include a truly non-processed way to get more
  // than one character at a time.

  if (in_file.readable())
    {
      while (!in_file.eof() && in_file.get(temp_char))
	{
	  if (buffer == NULL)
	    buffer = malloc(1);
	  else
	    buffer = realloc(buffer, i+1);
	  buffer[i] = temp_char;
	  i++;
	}
    }
  
  if (buffer != NULL)
    {
      buffer = realloc(buffer, i + 1);
      buffer[i] = 0;
      return buffer;
    }
  else return string_to_update;
};
