# include "opihi.h"

# define opihi_name "MANA"
# define opihi_prompt "mana: "
# define opihi_description "an image manipulation tool\n"
# define opihi_history ".mana"
# define opihi_rcfile ".manarc"

void InitBasic ();
void InitData ();
void InitAstro ();


void welcome () {
  fprintf (stderr, "\n");
  fprintf (stderr, "Welcome to %s - %s\n\n", opihi_name, opihi_description);
}

/* program-dependent initialization */
void initialize (int argc, char **argv) {
  
  FILE *f;

  auto_break = TRUE;

  Nlists = 0;
  ALLOCATE (lists, List, 1); 

  /* init functions required by libraries */
  /* -libopihi */
  InitCommands ();
  InitMacros ();
  InitBuffers ();
  InitVectors ();
  InitVariables ();

  /* -libdisplay */
  InitGraph ();
  InitImage ();

  /* load the commands used by this implementation */
  InitBasic ();
  InitData ();
  InitAstro ();
  InitOutfile ();

  rl_readline_name = opihi_name;
  rl_attempted_completion_function = command_completer;

  set_str_variable ("HISTORY", opihi_history);
  set_str_variable ("PROMPT", opihi_prompt);
  set_str_variable ("RCFILE", opihi_rcfile);

  /* here we open the history file for append.  it this fails, we
     won't be able to write to it, warn the user.  otherwise, this
     creates the file readline will write to, if it did not exist */  

  /* check history file */
  /* rewrite with fstat or stat */
  f = fopen (opihi_history, "a");
  if (f == NULL) /* no current history file here */
    fprintf (stderr, "can't save history.\n");
  else
    fclose (f);
  
  stifle_history (200);
  read_history (opihi_history);

  signal (SIGINT, SIG_IGN);
  return;
}

/* add program-dependent exit functions here */
void cleanup () {
  /* -libdisplay */
  QuitImage ();
  QuitGraph ();
  return;
}
