# include "data.h"

int erase (int argc, char **argv) {
  
  int i, n, N;
  char buffer[128];
  int Ximage, Nimage;
  
  Nimage = -1;
  if (N = get_argument (argc, argv, "-n")) {
    remove_argument (N, &argc, argv);
    Nimage = atof (argv[N]);
    remove_argument (N, &argc, argv);
  }
  if (!GetImage (&Ximage, &Nimage)) return (FALSE);

  if (argc < 2) {
    fprintf (stderr, "USAGE: erase (overlay) [overlay, overlay, ..] \n");
    fprintf (stderr, " (overlay) may be: red (0), green (1), blue (2), yellow (3) or all\n");
    return (FALSE);
  }

  for (i = 1; i < argc; i++) {
    if (strcmp (argv[i], "0")   && strcmp (argv[i], "1")     && strcmp (argv[i], "2")   && strcmp (argv[i], "3") &&
	strcmp (argv[i], "red") && strcmp (argv[i], "green") && strcmp (argv[i], "blue") && strcmp (argv[i], "yellow") &&
	strcmp (argv[i], "all") && strcmp (argv[i], "tick") ) {
      fprintf (stderr, "%s is not a valid overlay\n", argv[i]);
      return (FALSE);
    }
    n = atof (argv[i]);
    if (!(strcmp (argv[i], "all"))) {
      for (n = 0; n < 4; n++) {
	write (Ximage, "ERAS", 4); /* force Ximage to look for the incoming image */
	sprintf (buffer, "OVERLAY %7d ", n);
	write (Ximage, buffer, 16);
      }
      return (TRUE);
    }
    
    if (!(strcmp (argv[i], "red"))) n = 0;
    if (!(strcmp (argv[i], "green"))) n = 1;
    if (!(strcmp (argv[i], "blue"))) n = 2;
    if (!(strcmp (argv[i], "yellow"))) n = 3;
    if (!(strcmp (argv[i], "tick"))) n = 4;
    
    write (Ximage, "ERAS", 4); /* force Ximage to look for the incoming image */
    sprintf (buffer, "OVERLAY %7d ", n);
    write (Ximage, buffer, 16);
  }

  return (TRUE);
  
}
