# include "addstar.h"

int main (int argc, char **argv) {

  int Nstars, Nimages;
  int BindSocket;
  AddstarClientOptions options;
  Stars *stars;
  Image *images;

  /* load config and options */
  options = ConfigInit (&argc, argv);
  options = args_client (argc, argv, options);

  /* set up server connection */
  BindSocket = GetClientSocket (HOSTNAME);
  SendCommand (BindSocket, strlen(PASSWORD), PASSWORD);

  /* send new data to server */
  switch (options.mode) {
    case M_IMAGE:
      /* load data */
      stars = gstars (argv[1], &Nstars, &images, &Nimages, options.photcode);

      /* send data to server */
      SendCommand (BindSocket, 5, "IMAGE");
      Send_AddstarClientOptions (BindSocket, &options, 1, TRUE);
      Send_Image (BindSocket, images, Nimages, FALSE);
      if (options.mosaic) {
	Send_Coords (BindSocket, MOSAIC, 1, FALSE);
      }
      Send_Stars (BindSocket, stars, Nstars, FALSE);
      break;

    case M_REFLIST:
      /* load data */
      stars = grefstars (argv[1], options.photcode, &Nstars);
      
      /* send data to server */
      SendCommand (BindSocket, 5, "REFLS");
      Send_AddstarClientOptions (BindSocket, &options, 1, TRUE);
      Send_Stars (BindSocket, stars, Nstars, FALSE);
      break;

    case M_REFCAT:
      /* send data to server */
      SendCommand (BindSocket, 5, "REFCT");
      Send_AddstarClientOptions (BindSocket, &options, 1, TRUE);
      Send_SkyRegion (BindSocket, &UserPatch, 1, TRUE);
      SendMessage (BindSocket, argv[1]);
      break;

    default:
      fprintf (stderr, "unknown addstar mode\n");
      exit (1);
  }
  exit (0);
}
