#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
  char master[1024], new[1024];
  char *s;
  FILE *skeezix = fopen("SKEEZIX.TRACE", "r");
  FILE *retrocade = fopen("retro.log", "r");
  int lines = 0;
  int i;

  /* File 1 param is skeezix's trace of a tailgunner run */
  /* File 2 is my trace.  Read from both in synch until */
  /* a difference is found.  Print context and exit.   */
  /* Take care in places where our formats don't match */
  /* Such as shifts and WAI instructions.              */

  for (i = 0; ; i++) {
    for (;;) {
      strcpy(master, "                                                             ");
      s = fgets(master, 1023, skeezix);
      if (s == NULL) {
        fprintf(stdout, "Success!  You got to the end of the listing!\n");
        exit(0);
      }
      s = strchr(master, '\n'); if (s != NULL) *s = '\0';
      /* Discard junk for now */
      if (master[26] == ':') break;
    }
    /* Get corresponding line from mine. */

    for (;;) {
      /* Get a line from the new test stream */
      s = fgets(new, 1023, retrocade);
      if (s == NULL) {
        fprintf(stdout, "Error?  Premature close on stdin?  %d lines OK\n", lines);
        exit(1);
      }
      s = strchr(new, '\n'); if (s != NULL) *s = '\0';
      lines += 1;
      if (new[26] == ':') break;

    }
    /* Compare */
    if (strcmp(master, new) != 0) {
      fprintf(stdout, "%s SKEEZIX\n%s ME\n", master, new);
      exit(1);
    }
  }

  exit(0);
}
