# include "addstar.h"
# define NARGS 2  /* minimum is: addstar (filename) */

void help () {

  fprintf (stderr, "USAGE: addstar (filename)\n");
  fprintf (stderr, "  optional flags:\n");
  fprintf (stderr, "  -v (verbose mode)\n");
  fprintf (stderr, "  -p (photcode) - define the photcode\n");
  fprintf (stderr, "\n"); 
  exit (2);

}

int args (int argc, char **argv) {
  
  int N;

  /* check for help request */
  if (get_argument (argc, argv, "-help") ||
      get_argument (argc, argv, "-h")) {
    help ();
  }

  /* configuration info */
  ConfigInit (&argc, argv);

  /* check for command line options */
  VERBOSE = FALSE;
  if ((N = get_argument (argc, argv, "-v"))) {
    VERBOSE = TRUE;
    remove_argument (N, &argc, argv);
  }
  ACCEPT_ASTROM = FALSE;
  if ((N = get_argument (argc, argv, "-accept"))) {
    ACCEPT_ASTROM = TRUE;
    remove_argument (N, &argc, argv);
  }
  thiscode = NULL;
  if ((N = get_argument (argc, argv, "-p"))) {
    remove_argument (N, &argc, argv);
    thiscode = GetPhotcodebyName (argv[N]);
    remove_argument (N, &argc, argv);
  }
  DUMP_MATCHES = FALSE;
  if ((N = get_argument (argc, argv, "-dump"))) {
    DUMP_MATCHES = TRUE;
    remove_argument (N, &argc, argv);
  }
  FORCE_READ = FALSE;
  if ((N = get_argument (argc, argv, "-force"))) {
    remove_argument (N, &argc, argv);
    FORCE_READ = TRUE;
  }
  SKIP_MISSED = FALSE;
  if ((N = get_argument (argc, argv, "-missed"))) {
    SKIP_MISSED = TRUE;
    remove_argument (N, &argc, argv);
  }
  ONLY_IMAGES = FALSE;
  if ((N = get_argument (argc, argv, "-image"))) {
    ONLY_IMAGES = TRUE;
    remove_argument (N, &argc, argv);
  }
  CALIBRATE = FALSE;
  if ((N = get_argument (argc, argv, "-cal"))) {
    CALIBRATE = TRUE;
    remove_argument (N, &argc, argv);
    CalReference = GetPhotcodeCodebyName (argv[N]);
    if (!CalReference) {
      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", argv[N]);
      exit (1);
    }
    remove_argument (N, &argc, argv);
    CalColor = GetPhotcodeCodebyName (argv[N]);
    if (!CalColor) {
      fprintf (stderr, "ERROR: photcode color %s not found in photcode table\n", argv[N]);
      exit (1);
    }
    remove_argument (N, &argc, argv);
  }
  if (DUMP_MATCHES && !CALIBRATE) {
    fprintf (stderr, "-dump only valid -with -cal\n");
    exit (1);
  }

  if (argc != 2) {
    fprintf (stderr, "USAGE: addstar (filename) [-dump] [-image] [-v] [-p photcode] [-accept] [-cal code1 code2]\n");
    exit (2);
  }
  return (TRUE);
}

