# include "dvoshell.h"

# define opihi_name "DVO"
# define opihi_prompt "dvo: "
# define opihi_description "desktop virtual observatory\n"
# define opihi_history ".dvo"
# define opihi_rcfile ".dvorc"

/* program-dependent initialization */
void program_init (int *argc, char **argv) {
  
  auto_break = TRUE;

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

  if (!SetCATDIR (NULL, FALSE)) {
    gprint (GP_ERR, "CATDIR is not defined\n");
  }

  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);

# ifdef DATADIR_DEFAULT
  {
    char *datadir;
    char *helpdir;
    char *modules;
    datadir = MACRO_NAME(DATADIR_DEFAULT);
    /* set_str_variable ("DATADIR", datadir); */
    ALLOCATE (helpdir, char, strlen(datadir) + strlen("/help") + 2);
    sprintf (helpdir, "%s/help", datadir);
    set_str_variable ("HELPDIR", helpdir);
    free (helpdir);
    ALLOCATE (modules, char, strlen(datadir) + strlen("/modules") + 2);
    sprintf (modules, "%s/modules", datadir);
    set_str_variable ("MODULES:0", modules);
    set_int_variable ("MODULES:n", 1);
    free (modules);
  }
# endif

  return;
}

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

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

/* call to opihi shell */
int main (int argc, char **argv) {
  int status;
  status = opihi (argc, argv);
  exit (status);
}
