# include "scheduler.h"

# define opihi_name "scheduler"
# define opihi_prompt "sched: "
# define opihi_description "parallel task scheduler\n"
# define opihi_history ".sched"
# define opihi_rcfile ".schedrc"

/* program-dependent initialization */
void initialize (int argc, char **argv) {
  
  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 ();
  InitData ();
  InitSched ();
  InitTasks ();
  InitJobs ();
  InitJobIDs ();

  rl_readline_name = opihi_name;
  rl_attempted_completion_function = command_completer;
  rl_event_hook = NULL;
  rl_set_keyboard_input_timeout (1000000); 

  set_str_variable ("HISTORY", opihi_history);
  set_str_variable ("PROMPT", opihi_prompt);
  set_str_variable ("RCFILE", opihi_rcfile);
# ifdef HELPDIR_DEFAULT
  set_str_variable ("HELPDIR", MACRO_NAME(HELPDIR_DEFAULT));
# endif

  { /* check history file permission */
    FILE *f;
    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;
}

/* standard welcome message */
void welcome () {
  gprint (GP_LOG, "\n");
  gprint (GP_LOG, "Welcome to %s - %s\n\n", opihi_name, opihi_description);
}

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