# include "opihi.h"

# define opihi_name "Opihi"
# define opihi_prompt "opihi: "
# define opihi_description "Opihi - test shell\n"
# define opihi_history ".opihi"
# define opihi_rcfile ".opihirc"

void InitBasic ();

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

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

  auto_break = TRUE;

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

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

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

  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 */
    gprint (GP_ERR, "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;
}
