/* dinconv.c
   Copyright (C) 1991 by James R. Larus (larus@cs.wisc.edu).
   Author: Satish Chandra
   All rights reserved. */

/* $Header: /home/primost/larus/UW/Funding/WWT.DARPA/RCS/reg-audit.c,v 1.16 1991/12/09 23:01:52 larus Exp larus $ */


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

#include "caudit.h"

/* Local functions: */

static void perform_din_conversion();

/* Local variables: */

static ADDR pc;

static INST inst;

int
main (int argc, char *argv[])
{
  int i;
  char *file_name = NULL;

  if (argc != 2)
    fatal_error("Usage: dinconv binary_file\n");
  else 
    file_name = argv[1];
    
  read_aout (file_name);

  perform_din_conversion();   
  return (0);
}

static void
perform_din_conversion()
{
  char buf[80];
  char c;
  int count = 0;

  while ((c = getchar()) != EOF)
    {
      count++;
      switch (c)
	{
	case '0':
	case '1':
	  putchar(c);
	  fscanf(stdin, "%s\n", buf);
	  printf(" %s %c\n", buf, '0');
	  break;
	case '2':
	  putchar(c);
	  if (fscanf(stdin, "%s\n", buf) != 1)
	    fatal_error("Unable to read address\n");
	  if (sscanf(buf, "%x", &pc) != 1)
            {	
	        fprintf(stderr,"%d: %s\n", count, buf);	
		fatal_error("Unable to convert to address\n");
	    }
	  if ((pc < text_start) || (pc >= text_end))
	    {
	      fprintf(stderr,"%d: %s\n", count, buf);
	      fatal_error("PC out of bounds\n");
	    }
	  else
	    inst = GET_INST(pc);
	  printf(" %s %x\n", buf, inst);
	  break;
	default:
	  fatal_error("Format error in input din file!\n");
	}
    }
}






