# include "dvoshell.h"

int gcat (int argc, char **argv) {
  
  int i;
  struct stat filestat;
  double Ra, Dec, Radius;
  SkyTable *sky;
  SkyList *skylist;
  void *Signal;

  if ((argc != 3) && (argc != 4)) {
    gprint (GP_ERR, "USAGE: gcat RA DEC [Radius]\n");
    return (FALSE);
  }

  /* load sky from correct table */
  Ra = atof (argv[1]);
  Dec = atof (argv[2]);
  if (argc == 4) 
    Radius = atof(argv[3]);
  else 
    Radius = 0.0001;

  sky = GetSkyTable ();
  skylist = SkyListByRadius (sky, -1, Ra, Dec, Radius);

  // prepare to handle interrupt signals
  Signal = signal (SIGINT, handle_interrupt);
  interrupt = FALSE;

  for (i = 0; (i < skylist[0].Nregions) && !interrupt; i++) {
    if (stat (skylist[0].filename[i], &filestat) != -1) {
      gprint (GP_ERR, "%3d %s *\n", i, skylist[0].regions[i][0].name);
    } else {
      gprint (GP_ERR, "%3d %s\n", i, skylist[0].regions[i][0].name);
    } 
    set_str_variable ("CATNAME", skylist[0].filename[i]);
  }

  return (TRUE);
  SkyListFree (skylist);
}
