/*
 * subroutine for reading records from Ultrix traces
 * $Header: /tmp_mnt/n/fs/grad1/pc/src/iotrace/rtlib/RCS/readrec.c,v 1.2 94/01/06 14:07:16 pc Exp Locker: pc $
 */

#include <stdio.h>
#include "iotrace.h"
//#include "record.h"

int main(int argc, char **argv)
{
  FILE * tracefile;
  char buf[4];
  short tmp;
  struct tracerecord record;

  if (argc < 2)
    printf("Need trace file name!\n");

  tracefile = fopen(argv[1], "r");
  if (tracefile == NULL) {
    printf("Can't open trace file %s\n", argv[1]);
    exit(1);
  }

  while (fread(&record, sizeof(struct tracerecord), 1, tracefile) !=0) 
    {
      // switch endian
      *(short *)buf = record.op;
      tmp = buf[0];
      buf[0] = buf[1];
      buf[1] = buf[0];
      record.op = *(short *)buf;

      if (record.op < 0 || record.op > 3008)
	printf("Invalid op code\n");
    } // end of while

  fclose(tracefile);

  return 0;
}
