# include <ohana.h>
# include <gfitsio.h>

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

  int N, Extend, Nextend, status;
  int i, j, nbytes;
  Header head;
  char *p;

  Extend = FALSE;
  if ((N = get_argument (argc, argv, "-x"))) {
    Extend = TRUE;
    remove_argument (N, &argc, argv);
    Nextend = atoi (argv[N]);
    remove_argument (N, &argc, argv);
  }

  for (i = 1; i < argc; i++) {
    if (argc != 2) 
      fprintf (stdout, "------> %s <------\n", argv[i]);
    
    if (Extend) {
      status = gfits_read_Xheader (argv[i], &head, Nextend);
    } else {
      status = gfits_read_header (argv[i], &head);
    }      

    if (!status) continue;

    for (j = 79; j < head.size; j+= 80) {
      head.buffer[j] = 10;
    }

    p = gfits_header_field (&head, "END", 1);
    nbytes = p - head.buffer;
    fwrite (head.buffer, nbytes, 1, stdout);
    gfits_free_header (&head);

  }
  exit (0);
}
