sysdump.c revision 130561
133965Sjdp/* Sysroff object format dumper.
2130561Sobrien   Copyright 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003
389857Sobrien   Free Software Foundation, Inc.
433965Sjdp
538889Sjdp   This file is part of GNU Binutils.
633965Sjdp
738889Sjdp   This program is free software; you can redistribute it and/or modify
838889Sjdp   it under the terms of the GNU General Public License as published by
938889Sjdp   the Free Software Foundation; either version 2 of the License, or
1038889Sjdp   (at your option) any later version.
1133965Sjdp
1238889Sjdp   This program is distributed in the hope that it will be useful,
1338889Sjdp   but WITHOUT ANY WARRANTY; without even the implied warranty of
1438889Sjdp   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1538889Sjdp   GNU General Public License for more details.
1633965Sjdp
1738889Sjdp   You should have received a copy of the GNU General Public License
1838889Sjdp   along with this program; if not, write to the Free Software
1938889Sjdp   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
2038889Sjdp   02111-1307, USA.  */
2133965Sjdp
2233965Sjdp
2333965Sjdp/* Written by Steve Chamberlain <sac@cygnus.com>.
2433965Sjdp
2533965Sjdp This program reads a SYSROFF object file and prints it in an
2689857Sobrien almost human readable form to stdout.  */
2733965Sjdp
2833965Sjdp#include "bfd.h"
2933965Sjdp#include "bucomm.h"
3089857Sobrien#include "safe-ctype.h"
3133965Sjdp
3233965Sjdp#include <stdio.h>
33104834Sobrien#include "libiberty.h"
34104834Sobrien#include "getopt.h"
3533965Sjdp#include "sysroff.h"
3633965Sjdp
3733965Sjdpstatic int dump = 1;
3833965Sjdpstatic int segmented_p;
3933965Sjdpstatic int code;
4038889Sjdpstatic int addrsize = 4;
4133965Sjdpstatic FILE *file;
4233965Sjdp
43130561Sobrienstatic void dh (unsigned char *, int);
44130561Sobrienstatic void itheader (char *, int);
45130561Sobrienstatic void p (void);
46130561Sobrienstatic void tabout (void);
47130561Sobrienstatic void pbarray (barray *);
48130561Sobrienstatic int getone (int);
49130561Sobrienstatic int opt (int);
50130561Sobrienstatic void must (int);
51130561Sobrienstatic void tab (int, char *);
52130561Sobrienstatic void dump_symbol_info (void);
53130561Sobrienstatic void derived_type (void);
54130561Sobrienstatic void module (void);
55130561Sobrienstatic void show_usage (FILE *, int);
5689857Sobrien
57130561Sobrienextern char *getCHARS (unsigned char *, int *, int, int);
58130561Sobrienextern int fillup (char *);
59130561Sobrienextern barray getBARRAY (unsigned char *, int *, int, int);
60130561Sobrienextern int getINT (unsigned char *, int *, int, int);
61130561Sobrienextern int getBITS (char *, int *, int, int);
62130561Sobrienextern void sysroff_swap_tr_in (void);
63130561Sobrienextern void sysroff_print_tr_out (void);
64130561Sobrienextern int main (int, char **);
6589857Sobrien
6633965Sjdpchar *
67130561SobriengetCHARS (unsigned char *ptr, int *idx, int size, int max)
6833965Sjdp{
6933965Sjdp  int oc = *idx / 8;
7033965Sjdp  char *r;
7133965Sjdp  int b = size;
7289857Sobrien
7333965Sjdp  if (b >= max)
7489857Sobrien    return "*undefined*";
7533965Sjdp
7633965Sjdp  if (b == 0)
7733965Sjdp    {
7889857Sobrien      /* Got to work out the length of the string from self.  */
7933965Sjdp      b = ptr[oc++];
8033965Sjdp      (*idx) += 8;
8133965Sjdp    }
8233965Sjdp
8333965Sjdp  *idx += b * 8;
8433965Sjdp  r = xcalloc (b + 1, 1);
8533965Sjdp  memcpy (r, ptr + oc, b);
8633965Sjdp  r[b] = 0;
8789857Sobrien
8833965Sjdp  return r;
8933965Sjdp}
9033965Sjdp
9133965Sjdpstatic void
92130561Sobriendh (unsigned char *ptr, int size)
9333965Sjdp{
9433965Sjdp  int i;
9533965Sjdp  int j;
9633965Sjdp  int span = 16;
9733965Sjdp
9833965Sjdp  printf ("\n************************************************************\n");
9933965Sjdp
10033965Sjdp  for (i = 0; i < size; i += span)
10133965Sjdp    {
10233965Sjdp      for (j = 0; j < span; j++)
10333965Sjdp	{
104104834Sobrien	  if (j + i < size)
10533965Sjdp	    printf ("%02x ", ptr[i + j]);
106104834Sobrien	  else
107104834Sobrien	    printf ("   ");
10833965Sjdp	}
10933965Sjdp
11033965Sjdp      for (j = 0; j < span && j + i < size; j++)
11133965Sjdp	{
11233965Sjdp	  int c = ptr[i + j];
11389857Sobrien
11433965Sjdp	  if (c < 32 || c > 127)
11533965Sjdp	    c = '.';
11633965Sjdp	  printf ("%c", c);
11733965Sjdp	}
11889857Sobrien
11933965Sjdp      printf ("\n");
12033965Sjdp    }
12133965Sjdp}
12233965Sjdp
12333965Sjdpint
124130561Sobrienfillup (char *ptr)
12533965Sjdp{
12633965Sjdp  int size;
12733965Sjdp  int sum;
12833965Sjdp  int i;
12989857Sobrien
13033965Sjdp  size = getc (file) - 2;
13133965Sjdp  fread (ptr, 1, size, file);
13233965Sjdp  sum = code + size + 2;
13389857Sobrien
13433965Sjdp  for (i = 0; i < size; i++)
13589857Sobrien    sum += ptr[i];
13633965Sjdp
13733965Sjdp  if ((sum & 0xff) != 0xff)
13889857Sobrien    printf ("SUM IS %x\n", sum);
13989857Sobrien
14033965Sjdp  if (dump)
14133965Sjdp    dh (ptr, size);
14233965Sjdp
14333965Sjdp  return size - 1;
14433965Sjdp}
14533965Sjdp
14633965Sjdpbarray
147130561SobriengetBARRAY (unsigned char *ptr, int *idx, int dsize ATTRIBUTE_UNUSED,
148130561Sobrien	   int max ATTRIBUTE_UNUSED)
14933965Sjdp{
15033965Sjdp  barray res;
15133965Sjdp  int i;
15233965Sjdp  int byte = *idx / 8;
15333965Sjdp  int size = ptr[byte++];
15489857Sobrien
15533965Sjdp  res.len = size;
15633965Sjdp  res.data = (unsigned char *) xmalloc (size);
15789857Sobrien
15833965Sjdp  for (i = 0; i < size; i++)
15989857Sobrien    res.data[i] = ptr[byte++];
16089857Sobrien
16133965Sjdp  return res;
16233965Sjdp}
16333965Sjdp
16433965Sjdpint
165130561SobriengetINT (unsigned char *ptr, int *idx, int size, int max)
16633965Sjdp{
16733965Sjdp  int n = 0;
16833965Sjdp  int byte = *idx / 8;
16933965Sjdp
17033965Sjdp  if (byte >= max)
17189857Sobrien    return 0;
17289857Sobrien
17333965Sjdp  if (size == -2)
17438889Sjdp    size = addrsize;
17589857Sobrien
17633965Sjdp  if (size == -1)
17733965Sjdp    size = 0;
17889857Sobrien
17933965Sjdp  switch (size)
18033965Sjdp    {
18133965Sjdp    case 0:
18233965Sjdp      return 0;
18333965Sjdp    case 1:
18433965Sjdp      n = (ptr[byte]);
18533965Sjdp      break;
18633965Sjdp    case 2:
18733965Sjdp      n = (ptr[byte + 0] << 8) + ptr[byte + 1];
18833965Sjdp      break;
18933965Sjdp    case 4:
19033965Sjdp      n = (ptr[byte + 0] << 24) + (ptr[byte + 1] << 16) + (ptr[byte + 2] << 8) + (ptr[byte + 3]);
19133965Sjdp      break;
19233965Sjdp    default:
19333965Sjdp      abort ();
19433965Sjdp    }
19589857Sobrien
19633965Sjdp  *idx += size * 8;
19733965Sjdp  return n;
19833965Sjdp}
19933965Sjdp
20033965Sjdpint
201130561SobriengetBITS (char *ptr, int *idx, int size, int max)
20233965Sjdp{
20333965Sjdp  int byte = *idx / 8;
20433965Sjdp  int bit = *idx % 8;
20533965Sjdp
20638889Sjdp  if (byte >= max)
20738889Sjdp    return 0;
20838889Sjdp
20933965Sjdp  *idx += size;
21033965Sjdp
21133965Sjdp  return (ptr[byte] >> (8 - bit - size)) & ((1 << size) - 1);
21233965Sjdp}
21333965Sjdp
21433965Sjdpstatic void
215130561Sobrienitheader (char *name, int code)
21633965Sjdp{
21733965Sjdp  printf ("\n%s 0x%02x\n", name, code);
21833965Sjdp}
21933965Sjdp
22033965Sjdpstatic int indent;
22189857Sobrien
22233965Sjdpstatic void
223130561Sobrienp (void)
22433965Sjdp{
22533965Sjdp  int i;
22689857Sobrien
22733965Sjdp  for (i = 0; i < indent; i++)
22889857Sobrien    printf ("| ");
22989857Sobrien
23033965Sjdp  printf ("> ");
23133965Sjdp}
23233965Sjdp
23333965Sjdpstatic void
234130561Sobrientabout (void)
23533965Sjdp{
23633965Sjdp  p ();
23733965Sjdp}
23833965Sjdp
23933965Sjdpstatic void
240130561Sobrienpbarray (barray *y)
24133965Sjdp{
24233965Sjdp  int x;
24389857Sobrien
24433965Sjdp  printf ("%d (", y->len);
24589857Sobrien
24633965Sjdp  for (x = 0; x < y->len; x++)
24789857Sobrien    printf ("(%02x %c)", y->data[x],
24889857Sobrien	    ISPRINT (y->data[x]) ? y->data[x] : '.');
24989857Sobrien
25033965Sjdp  printf (")\n");
25133965Sjdp}
25233965Sjdp
25333965Sjdp#define SYSROFF_PRINT
25433965Sjdp#define SYSROFF_SWAP_IN
25533965Sjdp
25633965Sjdp#include "sysroff.c"
25733965Sjdp
25889857Sobrien/* FIXME: sysinfo, which generates sysroff.[ch] from sysroff.info, can't
25989857Sobrien   hack the special case of the tr block, which has no contents.  So we
26089857Sobrien   implement our own functions for reading in and printing out the tr
26189857Sobrien   block.  */
26233965Sjdp
26333965Sjdp#define IT_tr_CODE	0x7f
26489857Sobrien
26533965Sjdpvoid
266130561Sobriensysroff_swap_tr_in (void)
26733965Sjdp{
26889857Sobrien  char raw[255];
26933965Sjdp
27089857Sobrien  memset (raw, 0, 255);
27189857Sobrien  fillup (raw);
27233965Sjdp}
27333965Sjdp
27433965Sjdpvoid
275130561Sobriensysroff_print_tr_out (void)
27633965Sjdp{
27789857Sobrien  itheader ("tr", IT_tr_CODE);
27833965Sjdp}
27933965Sjdp
28033965Sjdpstatic int
281130561Sobriengetone (int type)
28233965Sjdp{
28333965Sjdp  int c = getc (file);
28489857Sobrien
28533965Sjdp  code = c;
28633965Sjdp
28733965Sjdp  if ((c & 0x7f) != type)
28833965Sjdp    {
28933965Sjdp      ungetc (c, file);
29033965Sjdp      return 0;
29133965Sjdp    }
29233965Sjdp
29333965Sjdp  switch (c & 0x7f)
29433965Sjdp    {
29533965Sjdp    case IT_cs_CODE:
29633965Sjdp      {
29733965Sjdp	struct IT_cs dummy;
29833965Sjdp	sysroff_swap_cs_in (&dummy);
29933965Sjdp	sysroff_print_cs_out (&dummy);
30033965Sjdp      }
30133965Sjdp      break;
30289857Sobrien
30333965Sjdp    case IT_dln_CODE:
30433965Sjdp      {
30533965Sjdp	struct IT_dln dummy;
30633965Sjdp	sysroff_swap_dln_in (&dummy);
30733965Sjdp	sysroff_print_dln_out (&dummy);
30833965Sjdp      }
30933965Sjdp      break;
31089857Sobrien
31133965Sjdp    case IT_hd_CODE:
31233965Sjdp      {
31333965Sjdp	struct IT_hd dummy;
31433965Sjdp	sysroff_swap_hd_in (&dummy);
31538889Sjdp	addrsize = dummy.afl;
31633965Sjdp	sysroff_print_hd_out (&dummy);
31733965Sjdp      }
31833965Sjdp      break;
31989857Sobrien
32033965Sjdp    case IT_dar_CODE:
32133965Sjdp      {
32233965Sjdp	struct IT_dar dummy;
32333965Sjdp	sysroff_swap_dar_in (&dummy);
32433965Sjdp	sysroff_print_dar_out (&dummy);
32533965Sjdp      }
32633965Sjdp      break;
32789857Sobrien
32833965Sjdp    case IT_dsy_CODE:
32933965Sjdp      {
33033965Sjdp	struct IT_dsy dummy;
33133965Sjdp	sysroff_swap_dsy_in (&dummy);
33233965Sjdp	sysroff_print_dsy_out (&dummy);
33333965Sjdp      }
33433965Sjdp      break;
33589857Sobrien
33633965Sjdp    case IT_dfp_CODE:
33733965Sjdp      {
33833965Sjdp	struct IT_dfp dummy;
33933965Sjdp	sysroff_swap_dfp_in (&dummy);
34033965Sjdp	sysroff_print_dfp_out (&dummy);
34133965Sjdp      }
34233965Sjdp      break;
34389857Sobrien
34433965Sjdp    case IT_dso_CODE:
34533965Sjdp      {
34633965Sjdp	struct IT_dso dummy;
34733965Sjdp	sysroff_swap_dso_in (&dummy);
34833965Sjdp	sysroff_print_dso_out (&dummy);
34933965Sjdp      }
35033965Sjdp      break;
35189857Sobrien
35233965Sjdp    case IT_dpt_CODE:
35333965Sjdp      {
35433965Sjdp	struct IT_dpt dummy;
35533965Sjdp	sysroff_swap_dpt_in (&dummy);
35633965Sjdp	sysroff_print_dpt_out (&dummy);
35733965Sjdp      }
35833965Sjdp      break;
35989857Sobrien
36033965Sjdp    case IT_den_CODE:
36133965Sjdp      {
36233965Sjdp	struct IT_den dummy;
36333965Sjdp	sysroff_swap_den_in (&dummy);
36433965Sjdp	sysroff_print_den_out (&dummy);
36533965Sjdp      }
36633965Sjdp      break;
36789857Sobrien
36833965Sjdp    case IT_dbt_CODE:
36933965Sjdp      {
37033965Sjdp	struct IT_dbt dummy;
37133965Sjdp	sysroff_swap_dbt_in (&dummy);
37233965Sjdp	sysroff_print_dbt_out (&dummy);
37333965Sjdp      }
37433965Sjdp      break;
37589857Sobrien
37633965Sjdp    case IT_dty_CODE:
37733965Sjdp      {
37833965Sjdp	struct IT_dty dummy;
37933965Sjdp	sysroff_swap_dty_in (&dummy);
38033965Sjdp	sysroff_print_dty_out (&dummy);
38133965Sjdp      }
38233965Sjdp      break;
38389857Sobrien
38433965Sjdp    case IT_un_CODE:
38533965Sjdp      {
38633965Sjdp	struct IT_un dummy;
38733965Sjdp	sysroff_swap_un_in (&dummy);
38833965Sjdp	sysroff_print_un_out (&dummy);
38933965Sjdp      }
39033965Sjdp      break;
39189857Sobrien
39233965Sjdp    case IT_sc_CODE:
39333965Sjdp      {
39433965Sjdp	struct IT_sc dummy;
39533965Sjdp	sysroff_swap_sc_in (&dummy);
39633965Sjdp	sysroff_print_sc_out (&dummy);
39733965Sjdp      }
39833965Sjdp      break;
39989857Sobrien
40033965Sjdp    case IT_er_CODE:
40133965Sjdp      {
40233965Sjdp	struct IT_er dummy;
40333965Sjdp	sysroff_swap_er_in (&dummy);
40433965Sjdp	sysroff_print_er_out (&dummy);
40533965Sjdp      }
40633965Sjdp      break;
40789857Sobrien
40833965Sjdp    case IT_ed_CODE:
40933965Sjdp      {
41033965Sjdp	struct IT_ed dummy;
41133965Sjdp	sysroff_swap_ed_in (&dummy);
41233965Sjdp	sysroff_print_ed_out (&dummy);
41333965Sjdp      }
41433965Sjdp      break;
41589857Sobrien
41633965Sjdp    case IT_sh_CODE:
41733965Sjdp      {
41833965Sjdp	struct IT_sh dummy;
41933965Sjdp	sysroff_swap_sh_in (&dummy);
42033965Sjdp	sysroff_print_sh_out (&dummy);
42133965Sjdp      }
42233965Sjdp      break;
42389857Sobrien
42433965Sjdp    case IT_ob_CODE:
42533965Sjdp      {
42633965Sjdp	struct IT_ob dummy;
42733965Sjdp	sysroff_swap_ob_in (&dummy);
42833965Sjdp	sysroff_print_ob_out (&dummy);
42933965Sjdp      }
43033965Sjdp      break;
43189857Sobrien
43233965Sjdp    case IT_rl_CODE:
43333965Sjdp      {
43433965Sjdp	struct IT_rl dummy;
43533965Sjdp	sysroff_swap_rl_in (&dummy);
43633965Sjdp	sysroff_print_rl_out (&dummy);
43733965Sjdp      }
43833965Sjdp      break;
43989857Sobrien
44033965Sjdp    case IT_du_CODE:
44133965Sjdp      {
44233965Sjdp	struct IT_du dummy;
44333965Sjdp	sysroff_swap_du_in (&dummy);
44433965Sjdp
44533965Sjdp	sysroff_print_du_out (&dummy);
44633965Sjdp      }
44733965Sjdp      break;
44889857Sobrien
44933965Sjdp    case IT_dus_CODE:
45033965Sjdp      {
45133965Sjdp	struct IT_dus dummy;
45233965Sjdp	sysroff_swap_dus_in (&dummy);
45333965Sjdp	sysroff_print_dus_out (&dummy);
45433965Sjdp      }
45533965Sjdp      break;
45689857Sobrien
45733965Sjdp    case IT_dul_CODE:
45833965Sjdp      {
45933965Sjdp	struct IT_dul dummy;
46033965Sjdp	sysroff_swap_dul_in (&dummy);
46133965Sjdp	sysroff_print_dul_out (&dummy);
46233965Sjdp      }
46333965Sjdp      break;
46489857Sobrien
46533965Sjdp    case IT_dss_CODE:
46633965Sjdp      {
46733965Sjdp	struct IT_dss dummy;
46833965Sjdp	sysroff_swap_dss_in (&dummy);
46933965Sjdp	sysroff_print_dss_out (&dummy);
47033965Sjdp      }
47133965Sjdp      break;
47289857Sobrien
47333965Sjdp    case IT_hs_CODE:
47433965Sjdp      {
47533965Sjdp	struct IT_hs dummy;
47633965Sjdp	sysroff_swap_hs_in (&dummy);
47733965Sjdp	sysroff_print_hs_out (&dummy);
47833965Sjdp      }
47933965Sjdp      break;
48089857Sobrien
48133965Sjdp    case IT_dps_CODE:
48233965Sjdp      {
48333965Sjdp	struct IT_dps dummy;
48433965Sjdp	sysroff_swap_dps_in (&dummy);
48533965Sjdp	sysroff_print_dps_out (&dummy);
48633965Sjdp      }
48733965Sjdp      break;
48889857Sobrien
48933965Sjdp    case IT_tr_CODE:
49089857Sobrien      sysroff_swap_tr_in ();
49189857Sobrien      sysroff_print_tr_out ();
49233965Sjdp      break;
49389857Sobrien
49433965Sjdp    case IT_dds_CODE:
49533965Sjdp      {
49633965Sjdp	struct IT_dds dummy;
49789857Sobrien
49833965Sjdp	sysroff_swap_dds_in (&dummy);
49933965Sjdp	sysroff_print_dds_out (&dummy);
50033965Sjdp      }
50133965Sjdp      break;
50289857Sobrien
50333965Sjdp    default:
50433965Sjdp      printf ("GOT A %x\n", c);
50533965Sjdp      return 0;
50633965Sjdp      break;
50733965Sjdp    }
50889857Sobrien
50933965Sjdp  return 1;
51033965Sjdp}
51133965Sjdp
51233965Sjdpstatic int
513130561Sobrienopt (int x)
51433965Sjdp{
51533965Sjdp  return getone (x);
51633965Sjdp}
51733965Sjdp
51838889Sjdp#if 0
51938889Sjdp
52038889Sjdp/* This is no longer used.  */
52138889Sjdp
52233965Sjdpstatic void
523130561Sobrienunit_info_list (void)
52433965Sjdp{
52533965Sjdp  while (opt (IT_un_CODE))
52633965Sjdp    {
52733965Sjdp      getone (IT_us_CODE);
52833965Sjdp
52933965Sjdp      while (getone (IT_sc_CODE))
53033965Sjdp	getone (IT_ss_CODE);
53133965Sjdp
53233965Sjdp      while (getone (IT_er_CODE))
53333965Sjdp	;
53433965Sjdp
53533965Sjdp      while (getone (IT_ed_CODE))
53633965Sjdp	;
53733965Sjdp    }
53833965Sjdp}
53933965Sjdp
54038889Sjdp#endif
54138889Sjdp
54238889Sjdp#if 0
54338889Sjdp
54438889Sjdp/* This is no longer used.  */
54538889Sjdp
54633965Sjdpstatic void
547130561Sobrienobject_body_list (void)
54833965Sjdp{
54933965Sjdp  while (getone (IT_sh_CODE))
55033965Sjdp    {
55133965Sjdp      while (getone (IT_ob_CODE))
55233965Sjdp	;
55333965Sjdp      while (getone (IT_rl_CODE))
55433965Sjdp	;
55533965Sjdp    }
55633965Sjdp}
55733965Sjdp
55838889Sjdp#endif
55938889Sjdp
56033965Sjdpstatic void
561130561Sobrienmust (int x)
56233965Sjdp{
56333965Sjdp  if (!getone (x))
56489857Sobrien    printf ("WANTED %x!!\n", x);
56533965Sjdp}
56633965Sjdp
56733965Sjdpstatic void
568130561Sobrientab (int i, char *s)
56933965Sjdp{
57033965Sjdp  indent += i;
57189857Sobrien
57233965Sjdp  if (s)
57333965Sjdp    {
57433965Sjdp      p ();
57533965Sjdp      printf (s);
57633965Sjdp      printf ("\n");
57733965Sjdp    }
57833965Sjdp}
57933965Sjdp
58033965Sjdpstatic void
581130561Sobriendump_symbol_info (void)
58233965Sjdp{
58333965Sjdp  tab (1, "SYMBOL INFO");
58489857Sobrien
58533965Sjdp  while (opt (IT_dsy_CODE))
58633965Sjdp    {
58733965Sjdp      if (opt (IT_dty_CODE))
58833965Sjdp	{
58933965Sjdp	  must (IT_dbt_CODE);
59033965Sjdp	  derived_type ();
59133965Sjdp	  must (IT_dty_CODE);
59233965Sjdp	}
59333965Sjdp    }
59489857Sobrien
59533965Sjdp  tab (-1, "");
59633965Sjdp}
59733965Sjdp
59833965Sjdpstatic void
599130561Sobrienderived_type (void)
60033965Sjdp{
60133965Sjdp  tab (1, "DERIVED TYPE");
60289857Sobrien
60333965Sjdp  while (1)
60433965Sjdp    {
60533965Sjdp      if (opt (IT_dpp_CODE))
60633965Sjdp	{
60733965Sjdp	  dump_symbol_info ();
60833965Sjdp	  must (IT_dpp_CODE);
60933965Sjdp	}
61033965Sjdp      else if (opt (IT_dfp_CODE))
61133965Sjdp	{
61233965Sjdp	  dump_symbol_info ();
61333965Sjdp	  must (IT_dfp_CODE);
61433965Sjdp	}
61533965Sjdp      else if (opt (IT_den_CODE))
61633965Sjdp	{
61733965Sjdp	  dump_symbol_info ();
61833965Sjdp	  must (IT_den_CODE);
61933965Sjdp	}
62033965Sjdp      else if (opt (IT_den_CODE))
62133965Sjdp	{
62233965Sjdp	  dump_symbol_info ();
62333965Sjdp	  must (IT_den_CODE);
62433965Sjdp	}
62533965Sjdp      else if (opt (IT_dds_CODE))
62633965Sjdp	{
62733965Sjdp	  dump_symbol_info ();
62833965Sjdp	  must (IT_dds_CODE);
62933965Sjdp	}
63033965Sjdp      else if (opt (IT_dar_CODE))
63133965Sjdp	{
63233965Sjdp	}
63333965Sjdp      else if (opt (IT_dpt_CODE))
63433965Sjdp	{
63533965Sjdp	}
63633965Sjdp      else if (opt (IT_dul_CODE))
63733965Sjdp	{
63833965Sjdp	}
63933965Sjdp      else if (opt (IT_dse_CODE))
64033965Sjdp	{
64133965Sjdp	}
64233965Sjdp      else if (opt (IT_dot_CODE))
64333965Sjdp	{
64433965Sjdp	}
64533965Sjdp      else
64633965Sjdp	break;
64733965Sjdp    }
64833965Sjdp
64933965Sjdp  tab (-1, "");
65033965Sjdp}
65133965Sjdp
65238889Sjdp#if 0
65338889Sjdp
65438889Sjdp/* This is no longer used.  */
65538889Sjdp
65633965Sjdpstatic void
657130561Sobrienprogram_structure (void)
65833965Sjdp{
65933965Sjdp  tab (1, "PROGRAM STRUCTURE");
66033965Sjdp  while (opt (IT_dps_CODE))
66133965Sjdp    {
66233965Sjdp      must (IT_dso_CODE);
66333965Sjdp      opt (IT_dss_CODE);
66433965Sjdp      dump_symbol_info ();
66533965Sjdp      must (IT_dps_CODE);
66633965Sjdp    }
66733965Sjdp  tab (-1, "");
66833965Sjdp}
66933965Sjdp
67038889Sjdp#endif
67138889Sjdp
67238889Sjdp#if 0
67338889Sjdp
67438889Sjdp/* This is no longer used.  */
67538889Sjdp
67633965Sjdpstatic void
677130561Sobriendebug_list (void)
67833965Sjdp{
67933965Sjdp  tab (1, "DEBUG LIST");
68033965Sjdp
68133965Sjdp  must (IT_du_CODE);
68233965Sjdp  opt (IT_dus_CODE);
68333965Sjdp  program_structure ();
68433965Sjdp  must (IT_dln_CODE);
68533965Sjdp
68633965Sjdp  tab (-1, "");
68733965Sjdp}
68833965Sjdp
68938889Sjdp#endif
69038889Sjdp
69133965Sjdpstatic void
692130561Sobrienmodule (void)
69333965Sjdp{
69433965Sjdp  int c = 0;
69533965Sjdp  int l = 0;
69633965Sjdp
69733965Sjdp  tab (1, "MODULE***\n");
69833965Sjdp
69933965Sjdp  do
70033965Sjdp    {
70133965Sjdp      c = getc (file);
70233965Sjdp      ungetc (c, file);
70333965Sjdp
70433965Sjdp      c &= 0x7f;
70533965Sjdp    }
70633965Sjdp  while (getone (c) && c != IT_tr_CODE);
70733965Sjdp
70833965Sjdp#if 0
70933965Sjdp  must (IT_cs_CODE);
71033965Sjdp  must (IT_hd_CODE);
71133965Sjdp  opt (IT_hs_CODE);
71233965Sjdp
71333965Sjdp  unit_info_list ();
71433965Sjdp  object_body_list ();
71533965Sjdp  debug_list ();
71633965Sjdp
71733965Sjdp  must (IT_tr_CODE);
71833965Sjdp#endif
71933965Sjdp  tab (-1, "");
72033965Sjdp
72133965Sjdp  c = getc (file);
72233965Sjdp  while (c != EOF)
72333965Sjdp    {
72433965Sjdp      printf ("%02x ", c);
72533965Sjdp      l++;
72633965Sjdp      if (l == 32)
72733965Sjdp	{
72833965Sjdp	  printf ("\n");
72933965Sjdp	  l = 0;
73033965Sjdp	}
73133965Sjdp      c = getc (file);
73233965Sjdp    }
73333965Sjdp}
73433965Sjdp
73533965Sjdpchar *program_name;
73633965Sjdp
73733965Sjdpstatic void
738130561Sobrienshow_usage (FILE *file, int status)
73933965Sjdp{
74089857Sobrien  fprintf (file, _("Usage: %s [option(s)] in-file\n"), program_name);
74189857Sobrien  fprintf (file, _("Print a human readable interpretation of a SYSROFF object file\n"));
74289857Sobrien  fprintf (file, _(" The options are:\n\
74389857Sobrien  -h --help        Display this information\n\
74489857Sobrien  -v --version     Print the program's version number\n"));
74589857Sobrien
74689857Sobrien  if (status == 0)
74789857Sobrien    fprintf (file, _("Report bugs to %s\n"), REPORT_BUGS_TO);
74833965Sjdp  exit (status);
74933965Sjdp}
75033965Sjdp
75133965Sjdpint
752130561Sobrienmain (int ac, char **av)
75333965Sjdp{
75433965Sjdp  char *input_file = NULL;
75533965Sjdp  int opt;
75633965Sjdp  static struct option long_options[] =
75733965Sjdp  {
75833965Sjdp    {"help", no_argument, 0, 'h'},
75933965Sjdp    {"version", no_argument, 0, 'V'},
76033965Sjdp    {NULL, no_argument, 0, 0}
76133965Sjdp  };
76233965Sjdp
76360484Sobrien#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
76460484Sobrien  setlocale (LC_MESSAGES, "");
76560484Sobrien#endif
76689857Sobrien#if defined (HAVE_SETLOCALE)
76789857Sobrien  setlocale (LC_CTYPE, "");
76889857Sobrien#endif
76960484Sobrien  bindtextdomain (PACKAGE, LOCALEDIR);
77060484Sobrien  textdomain (PACKAGE);
77160484Sobrien
77233965Sjdp  program_name = av[0];
77333965Sjdp  xmalloc_set_program_name (program_name);
77433965Sjdp
77589857Sobrien  while ((opt = getopt_long (ac, av, "HhVv", long_options, (int *) NULL)) != EOF)
77633965Sjdp    {
77733965Sjdp      switch (opt)
77833965Sjdp	{
77989857Sobrien	case 'H':
78033965Sjdp	case 'h':
78189857Sobrien	  show_usage (stdout, 0);
78233965Sjdp	  /*NOTREACHED*/
78389857Sobrien	case 'v':
78433965Sjdp	case 'V':
78589857Sobrien	  print_version ("sysdump");
78633965Sjdp	  exit (0);
78733965Sjdp	  /*NOTREACHED*/
78833965Sjdp	case 0:
78933965Sjdp	  break;
79033965Sjdp	default:
79133965Sjdp	  show_usage (stderr, 1);
79233965Sjdp	  /*NOTREACHED*/
79333965Sjdp	}
79433965Sjdp    }
79533965Sjdp
79633965Sjdp  /* The input and output files may be named on the command line.  */
79733965Sjdp
79833965Sjdp  if (optind < ac)
79989857Sobrien    input_file = av[optind];
80033965Sjdp
80133965Sjdp  if (!input_file)
80289857Sobrien    fatal (_("no input file specified"));
80333965Sjdp
80433965Sjdp  file = fopen (input_file, FOPEN_RB);
80589857Sobrien
80633965Sjdp  if (!file)
80789857Sobrien    fatal (_("cannot open input file %s"), input_file);
80833965Sjdp
80933965Sjdp  module ();
81033965Sjdp  return 0;
81133965Sjdp}
812