133965Sjdp/* Sysroff object format dumper.
2218822Sdim   Copyright 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007
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
19218822Sdim   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
20218822Sdim   02110-1301, 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
28218822Sdim#include "sysdep.h"
2933965Sjdp#include "bfd.h"
3089857Sobrien#include "safe-ctype.h"
31104834Sobrien#include "libiberty.h"
32104834Sobrien#include "getopt.h"
33218822Sdim#include "bucomm.h"
3433965Sjdp#include "sysroff.h"
3533965Sjdp
3633965Sjdpstatic int dump = 1;
3733965Sjdpstatic int segmented_p;
3833965Sjdpstatic int code;
3938889Sjdpstatic int addrsize = 4;
4033965Sjdpstatic FILE *file;
4133965Sjdp
42130561Sobrienstatic void dh (unsigned char *, int);
43130561Sobrienstatic void itheader (char *, int);
44130561Sobrienstatic void p (void);
45130561Sobrienstatic void tabout (void);
46130561Sobrienstatic void pbarray (barray *);
47130561Sobrienstatic int getone (int);
48130561Sobrienstatic int opt (int);
49130561Sobrienstatic void must (int);
50130561Sobrienstatic void tab (int, char *);
51130561Sobrienstatic void dump_symbol_info (void);
52130561Sobrienstatic void derived_type (void);
53130561Sobrienstatic void module (void);
54130561Sobrienstatic void show_usage (FILE *, int);
5589857Sobrien
56130561Sobrienextern int main (int, char **);
5789857Sobrien
58218822Sdimstatic char *
59130561SobriengetCHARS (unsigned char *ptr, int *idx, int size, int max)
6033965Sjdp{
6133965Sjdp  int oc = *idx / 8;
6233965Sjdp  char *r;
6333965Sjdp  int b = size;
6489857Sobrien
6533965Sjdp  if (b >= max)
6689857Sobrien    return "*undefined*";
6733965Sjdp
6833965Sjdp  if (b == 0)
6933965Sjdp    {
7089857Sobrien      /* Got to work out the length of the string from self.  */
7133965Sjdp      b = ptr[oc++];
7233965Sjdp      (*idx) += 8;
7333965Sjdp    }
7433965Sjdp
7533965Sjdp  *idx += b * 8;
7633965Sjdp  r = xcalloc (b + 1, 1);
7733965Sjdp  memcpy (r, ptr + oc, b);
7833965Sjdp  r[b] = 0;
7989857Sobrien
8033965Sjdp  return r;
8133965Sjdp}
8233965Sjdp
8333965Sjdpstatic void
84130561Sobriendh (unsigned char *ptr, int size)
8533965Sjdp{
8633965Sjdp  int i;
8733965Sjdp  int j;
8833965Sjdp  int span = 16;
8933965Sjdp
9033965Sjdp  printf ("\n************************************************************\n");
9133965Sjdp
9233965Sjdp  for (i = 0; i < size; i += span)
9333965Sjdp    {
9433965Sjdp      for (j = 0; j < span; j++)
9533965Sjdp	{
96104834Sobrien	  if (j + i < size)
9733965Sjdp	    printf ("%02x ", ptr[i + j]);
98104834Sobrien	  else
99104834Sobrien	    printf ("   ");
10033965Sjdp	}
10133965Sjdp
10233965Sjdp      for (j = 0; j < span && j + i < size; j++)
10333965Sjdp	{
10433965Sjdp	  int c = ptr[i + j];
10589857Sobrien
10633965Sjdp	  if (c < 32 || c > 127)
10733965Sjdp	    c = '.';
10833965Sjdp	  printf ("%c", c);
10933965Sjdp	}
11089857Sobrien
11133965Sjdp      printf ("\n");
11233965Sjdp    }
11333965Sjdp}
11433965Sjdp
115218822Sdimstatic int
116218822Sdimfillup (unsigned char *ptr)
11733965Sjdp{
11833965Sjdp  int size;
11933965Sjdp  int sum;
12033965Sjdp  int i;
12189857Sobrien
12233965Sjdp  size = getc (file) - 2;
12333965Sjdp  fread (ptr, 1, size, file);
12433965Sjdp  sum = code + size + 2;
12589857Sobrien
12633965Sjdp  for (i = 0; i < size; i++)
12789857Sobrien    sum += ptr[i];
12833965Sjdp
12933965Sjdp  if ((sum & 0xff) != 0xff)
13089857Sobrien    printf ("SUM IS %x\n", sum);
13189857Sobrien
13233965Sjdp  if (dump)
13333965Sjdp    dh (ptr, size);
13433965Sjdp
13533965Sjdp  return size - 1;
13633965Sjdp}
13733965Sjdp
138218822Sdimstatic barray
139130561SobriengetBARRAY (unsigned char *ptr, int *idx, int dsize ATTRIBUTE_UNUSED,
140130561Sobrien	   int max ATTRIBUTE_UNUSED)
14133965Sjdp{
14233965Sjdp  barray res;
14333965Sjdp  int i;
14433965Sjdp  int byte = *idx / 8;
14533965Sjdp  int size = ptr[byte++];
14689857Sobrien
14733965Sjdp  res.len = size;
14833965Sjdp  res.data = (unsigned char *) xmalloc (size);
14989857Sobrien
15033965Sjdp  for (i = 0; i < size; i++)
15189857Sobrien    res.data[i] = ptr[byte++];
15289857Sobrien
15333965Sjdp  return res;
15433965Sjdp}
15533965Sjdp
156218822Sdimstatic int
157130561SobriengetINT (unsigned char *ptr, int *idx, int size, int max)
15833965Sjdp{
15933965Sjdp  int n = 0;
16033965Sjdp  int byte = *idx / 8;
16133965Sjdp
16233965Sjdp  if (byte >= max)
16389857Sobrien    return 0;
16489857Sobrien
16533965Sjdp  if (size == -2)
16638889Sjdp    size = addrsize;
16789857Sobrien
16833965Sjdp  if (size == -1)
16933965Sjdp    size = 0;
17089857Sobrien
17133965Sjdp  switch (size)
17233965Sjdp    {
17333965Sjdp    case 0:
17433965Sjdp      return 0;
17533965Sjdp    case 1:
17633965Sjdp      n = (ptr[byte]);
17733965Sjdp      break;
17833965Sjdp    case 2:
17933965Sjdp      n = (ptr[byte + 0] << 8) + ptr[byte + 1];
18033965Sjdp      break;
18133965Sjdp    case 4:
18233965Sjdp      n = (ptr[byte + 0] << 24) + (ptr[byte + 1] << 16) + (ptr[byte + 2] << 8) + (ptr[byte + 3]);
18333965Sjdp      break;
18433965Sjdp    default:
18533965Sjdp      abort ();
18633965Sjdp    }
18789857Sobrien
18833965Sjdp  *idx += size * 8;
18933965Sjdp  return n;
19033965Sjdp}
19133965Sjdp
192218822Sdimstatic int
193218822SdimgetBITS (unsigned char *ptr, int *idx, int size, int max)
19433965Sjdp{
19533965Sjdp  int byte = *idx / 8;
19633965Sjdp  int bit = *idx % 8;
19733965Sjdp
19838889Sjdp  if (byte >= max)
19938889Sjdp    return 0;
20038889Sjdp
20133965Sjdp  *idx += size;
20233965Sjdp
20333965Sjdp  return (ptr[byte] >> (8 - bit - size)) & ((1 << size) - 1);
20433965Sjdp}
20533965Sjdp
20633965Sjdpstatic void
207130561Sobrienitheader (char *name, int code)
20833965Sjdp{
20933965Sjdp  printf ("\n%s 0x%02x\n", name, code);
21033965Sjdp}
21133965Sjdp
21233965Sjdpstatic int indent;
21389857Sobrien
21433965Sjdpstatic void
215130561Sobrienp (void)
21633965Sjdp{
21733965Sjdp  int i;
21889857Sobrien
21933965Sjdp  for (i = 0; i < indent; i++)
22089857Sobrien    printf ("| ");
22189857Sobrien
22233965Sjdp  printf ("> ");
22333965Sjdp}
22433965Sjdp
22533965Sjdpstatic void
226130561Sobrientabout (void)
22733965Sjdp{
22833965Sjdp  p ();
22933965Sjdp}
23033965Sjdp
23133965Sjdpstatic void
232130561Sobrienpbarray (barray *y)
23333965Sjdp{
23433965Sjdp  int x;
23589857Sobrien
23633965Sjdp  printf ("%d (", y->len);
23789857Sobrien
23833965Sjdp  for (x = 0; x < y->len; x++)
23989857Sobrien    printf ("(%02x %c)", y->data[x],
24089857Sobrien	    ISPRINT (y->data[x]) ? y->data[x] : '.');
24189857Sobrien
24233965Sjdp  printf (")\n");
24333965Sjdp}
24433965Sjdp
24533965Sjdp#define SYSROFF_PRINT
24633965Sjdp#define SYSROFF_SWAP_IN
24733965Sjdp
24833965Sjdp#include "sysroff.c"
24933965Sjdp
25089857Sobrien/* FIXME: sysinfo, which generates sysroff.[ch] from sysroff.info, can't
25189857Sobrien   hack the special case of the tr block, which has no contents.  So we
25289857Sobrien   implement our own functions for reading in and printing out the tr
25389857Sobrien   block.  */
25433965Sjdp
25533965Sjdp#define IT_tr_CODE	0x7f
25689857Sobrien
257218822Sdimstatic void
258130561Sobriensysroff_swap_tr_in (void)
25933965Sjdp{
260218822Sdim  unsigned char raw[255];
26133965Sjdp
26289857Sobrien  memset (raw, 0, 255);
26389857Sobrien  fillup (raw);
26433965Sjdp}
26533965Sjdp
266218822Sdimstatic void
267130561Sobriensysroff_print_tr_out (void)
26833965Sjdp{
26989857Sobrien  itheader ("tr", IT_tr_CODE);
27033965Sjdp}
27133965Sjdp
27233965Sjdpstatic int
273130561Sobriengetone (int type)
27433965Sjdp{
27533965Sjdp  int c = getc (file);
27689857Sobrien
27733965Sjdp  code = c;
27833965Sjdp
27933965Sjdp  if ((c & 0x7f) != type)
28033965Sjdp    {
28133965Sjdp      ungetc (c, file);
28233965Sjdp      return 0;
28333965Sjdp    }
28433965Sjdp
28533965Sjdp  switch (c & 0x7f)
28633965Sjdp    {
28733965Sjdp    case IT_cs_CODE:
28833965Sjdp      {
28933965Sjdp	struct IT_cs dummy;
29033965Sjdp	sysroff_swap_cs_in (&dummy);
29133965Sjdp	sysroff_print_cs_out (&dummy);
29233965Sjdp      }
29333965Sjdp      break;
29489857Sobrien
29533965Sjdp    case IT_dln_CODE:
29633965Sjdp      {
29733965Sjdp	struct IT_dln dummy;
29833965Sjdp	sysroff_swap_dln_in (&dummy);
29933965Sjdp	sysroff_print_dln_out (&dummy);
30033965Sjdp      }
30133965Sjdp      break;
30289857Sobrien
30333965Sjdp    case IT_hd_CODE:
30433965Sjdp      {
30533965Sjdp	struct IT_hd dummy;
30633965Sjdp	sysroff_swap_hd_in (&dummy);
30738889Sjdp	addrsize = dummy.afl;
30833965Sjdp	sysroff_print_hd_out (&dummy);
30933965Sjdp      }
31033965Sjdp      break;
31189857Sobrien
31233965Sjdp    case IT_dar_CODE:
31333965Sjdp      {
31433965Sjdp	struct IT_dar dummy;
31533965Sjdp	sysroff_swap_dar_in (&dummy);
31633965Sjdp	sysroff_print_dar_out (&dummy);
31733965Sjdp      }
31833965Sjdp      break;
31989857Sobrien
32033965Sjdp    case IT_dsy_CODE:
32133965Sjdp      {
32233965Sjdp	struct IT_dsy dummy;
32333965Sjdp	sysroff_swap_dsy_in (&dummy);
32433965Sjdp	sysroff_print_dsy_out (&dummy);
32533965Sjdp      }
32633965Sjdp      break;
32789857Sobrien
32833965Sjdp    case IT_dfp_CODE:
32933965Sjdp      {
33033965Sjdp	struct IT_dfp dummy;
33133965Sjdp	sysroff_swap_dfp_in (&dummy);
33233965Sjdp	sysroff_print_dfp_out (&dummy);
33333965Sjdp      }
33433965Sjdp      break;
33589857Sobrien
33633965Sjdp    case IT_dso_CODE:
33733965Sjdp      {
33833965Sjdp	struct IT_dso dummy;
33933965Sjdp	sysroff_swap_dso_in (&dummy);
34033965Sjdp	sysroff_print_dso_out (&dummy);
34133965Sjdp      }
34233965Sjdp      break;
34389857Sobrien
34433965Sjdp    case IT_dpt_CODE:
34533965Sjdp      {
34633965Sjdp	struct IT_dpt dummy;
34733965Sjdp	sysroff_swap_dpt_in (&dummy);
34833965Sjdp	sysroff_print_dpt_out (&dummy);
34933965Sjdp      }
35033965Sjdp      break;
35189857Sobrien
35233965Sjdp    case IT_den_CODE:
35333965Sjdp      {
35433965Sjdp	struct IT_den dummy;
35533965Sjdp	sysroff_swap_den_in (&dummy);
35633965Sjdp	sysroff_print_den_out (&dummy);
35733965Sjdp      }
35833965Sjdp      break;
35989857Sobrien
36033965Sjdp    case IT_dbt_CODE:
36133965Sjdp      {
36233965Sjdp	struct IT_dbt dummy;
36333965Sjdp	sysroff_swap_dbt_in (&dummy);
36433965Sjdp	sysroff_print_dbt_out (&dummy);
36533965Sjdp      }
36633965Sjdp      break;
36789857Sobrien
36833965Sjdp    case IT_dty_CODE:
36933965Sjdp      {
37033965Sjdp	struct IT_dty dummy;
37133965Sjdp	sysroff_swap_dty_in (&dummy);
37233965Sjdp	sysroff_print_dty_out (&dummy);
37333965Sjdp      }
37433965Sjdp      break;
37589857Sobrien
37633965Sjdp    case IT_un_CODE:
37733965Sjdp      {
37833965Sjdp	struct IT_un dummy;
37933965Sjdp	sysroff_swap_un_in (&dummy);
38033965Sjdp	sysroff_print_un_out (&dummy);
38133965Sjdp      }
38233965Sjdp      break;
38389857Sobrien
38433965Sjdp    case IT_sc_CODE:
38533965Sjdp      {
38633965Sjdp	struct IT_sc dummy;
38733965Sjdp	sysroff_swap_sc_in (&dummy);
38833965Sjdp	sysroff_print_sc_out (&dummy);
38933965Sjdp      }
39033965Sjdp      break;
39189857Sobrien
39233965Sjdp    case IT_er_CODE:
39333965Sjdp      {
39433965Sjdp	struct IT_er dummy;
39533965Sjdp	sysroff_swap_er_in (&dummy);
39633965Sjdp	sysroff_print_er_out (&dummy);
39733965Sjdp      }
39833965Sjdp      break;
39989857Sobrien
40033965Sjdp    case IT_ed_CODE:
40133965Sjdp      {
40233965Sjdp	struct IT_ed dummy;
40333965Sjdp	sysroff_swap_ed_in (&dummy);
40433965Sjdp	sysroff_print_ed_out (&dummy);
40533965Sjdp      }
40633965Sjdp      break;
40789857Sobrien
40833965Sjdp    case IT_sh_CODE:
40933965Sjdp      {
41033965Sjdp	struct IT_sh dummy;
41133965Sjdp	sysroff_swap_sh_in (&dummy);
41233965Sjdp	sysroff_print_sh_out (&dummy);
41333965Sjdp      }
41433965Sjdp      break;
41589857Sobrien
41633965Sjdp    case IT_ob_CODE:
41733965Sjdp      {
41833965Sjdp	struct IT_ob dummy;
41933965Sjdp	sysroff_swap_ob_in (&dummy);
42033965Sjdp	sysroff_print_ob_out (&dummy);
42133965Sjdp      }
42233965Sjdp      break;
42389857Sobrien
42433965Sjdp    case IT_rl_CODE:
42533965Sjdp      {
42633965Sjdp	struct IT_rl dummy;
42733965Sjdp	sysroff_swap_rl_in (&dummy);
42833965Sjdp	sysroff_print_rl_out (&dummy);
42933965Sjdp      }
43033965Sjdp      break;
43189857Sobrien
43233965Sjdp    case IT_du_CODE:
43333965Sjdp      {
43433965Sjdp	struct IT_du dummy;
43533965Sjdp	sysroff_swap_du_in (&dummy);
43633965Sjdp
43733965Sjdp	sysroff_print_du_out (&dummy);
43833965Sjdp      }
43933965Sjdp      break;
44089857Sobrien
44133965Sjdp    case IT_dus_CODE:
44233965Sjdp      {
44333965Sjdp	struct IT_dus dummy;
44433965Sjdp	sysroff_swap_dus_in (&dummy);
44533965Sjdp	sysroff_print_dus_out (&dummy);
44633965Sjdp      }
44733965Sjdp      break;
44889857Sobrien
44933965Sjdp    case IT_dul_CODE:
45033965Sjdp      {
45133965Sjdp	struct IT_dul dummy;
45233965Sjdp	sysroff_swap_dul_in (&dummy);
45333965Sjdp	sysroff_print_dul_out (&dummy);
45433965Sjdp      }
45533965Sjdp      break;
45689857Sobrien
45733965Sjdp    case IT_dss_CODE:
45833965Sjdp      {
45933965Sjdp	struct IT_dss dummy;
46033965Sjdp	sysroff_swap_dss_in (&dummy);
46133965Sjdp	sysroff_print_dss_out (&dummy);
46233965Sjdp      }
46333965Sjdp      break;
46489857Sobrien
46533965Sjdp    case IT_hs_CODE:
46633965Sjdp      {
46733965Sjdp	struct IT_hs dummy;
46833965Sjdp	sysroff_swap_hs_in (&dummy);
46933965Sjdp	sysroff_print_hs_out (&dummy);
47033965Sjdp      }
47133965Sjdp      break;
47289857Sobrien
47333965Sjdp    case IT_dps_CODE:
47433965Sjdp      {
47533965Sjdp	struct IT_dps dummy;
47633965Sjdp	sysroff_swap_dps_in (&dummy);
47733965Sjdp	sysroff_print_dps_out (&dummy);
47833965Sjdp      }
47933965Sjdp      break;
48089857Sobrien
48133965Sjdp    case IT_tr_CODE:
48289857Sobrien      sysroff_swap_tr_in ();
48389857Sobrien      sysroff_print_tr_out ();
48433965Sjdp      break;
48589857Sobrien
48633965Sjdp    case IT_dds_CODE:
48733965Sjdp      {
48833965Sjdp	struct IT_dds dummy;
48989857Sobrien
49033965Sjdp	sysroff_swap_dds_in (&dummy);
49133965Sjdp	sysroff_print_dds_out (&dummy);
49233965Sjdp      }
49333965Sjdp      break;
49489857Sobrien
49533965Sjdp    default:
49633965Sjdp      printf ("GOT A %x\n", c);
49733965Sjdp      return 0;
49833965Sjdp      break;
49933965Sjdp    }
50089857Sobrien
50133965Sjdp  return 1;
50233965Sjdp}
50333965Sjdp
50433965Sjdpstatic int
505130561Sobrienopt (int x)
50633965Sjdp{
50733965Sjdp  return getone (x);
50833965Sjdp}
50933965Sjdp
51033965Sjdpstatic void
511130561Sobrienmust (int x)
51233965Sjdp{
51333965Sjdp  if (!getone (x))
51489857Sobrien    printf ("WANTED %x!!\n", x);
51533965Sjdp}
51633965Sjdp
51733965Sjdpstatic void
518130561Sobrientab (int i, char *s)
51933965Sjdp{
52033965Sjdp  indent += i;
52189857Sobrien
52233965Sjdp  if (s)
52333965Sjdp    {
52433965Sjdp      p ();
52533965Sjdp      printf (s);
52633965Sjdp      printf ("\n");
52733965Sjdp    }
52833965Sjdp}
52933965Sjdp
53033965Sjdpstatic void
531130561Sobriendump_symbol_info (void)
53233965Sjdp{
53333965Sjdp  tab (1, "SYMBOL INFO");
53489857Sobrien
53533965Sjdp  while (opt (IT_dsy_CODE))
53633965Sjdp    {
53733965Sjdp      if (opt (IT_dty_CODE))
53833965Sjdp	{
53933965Sjdp	  must (IT_dbt_CODE);
54033965Sjdp	  derived_type ();
54133965Sjdp	  must (IT_dty_CODE);
54233965Sjdp	}
54333965Sjdp    }
54489857Sobrien
54533965Sjdp  tab (-1, "");
54633965Sjdp}
54733965Sjdp
54833965Sjdpstatic void
549130561Sobrienderived_type (void)
55033965Sjdp{
55133965Sjdp  tab (1, "DERIVED TYPE");
55289857Sobrien
55333965Sjdp  while (1)
55433965Sjdp    {
55533965Sjdp      if (opt (IT_dpp_CODE))
55633965Sjdp	{
55733965Sjdp	  dump_symbol_info ();
55833965Sjdp	  must (IT_dpp_CODE);
55933965Sjdp	}
56033965Sjdp      else if (opt (IT_dfp_CODE))
56133965Sjdp	{
56233965Sjdp	  dump_symbol_info ();
56333965Sjdp	  must (IT_dfp_CODE);
56433965Sjdp	}
56533965Sjdp      else if (opt (IT_den_CODE))
56633965Sjdp	{
56733965Sjdp	  dump_symbol_info ();
56833965Sjdp	  must (IT_den_CODE);
56933965Sjdp	}
57033965Sjdp      else if (opt (IT_den_CODE))
57133965Sjdp	{
57233965Sjdp	  dump_symbol_info ();
57333965Sjdp	  must (IT_den_CODE);
57433965Sjdp	}
57533965Sjdp      else if (opt (IT_dds_CODE))
57633965Sjdp	{
57733965Sjdp	  dump_symbol_info ();
57833965Sjdp	  must (IT_dds_CODE);
57933965Sjdp	}
58033965Sjdp      else if (opt (IT_dar_CODE))
58133965Sjdp	{
58233965Sjdp	}
58333965Sjdp      else if (opt (IT_dpt_CODE))
58433965Sjdp	{
58533965Sjdp	}
58633965Sjdp      else if (opt (IT_dul_CODE))
58733965Sjdp	{
58833965Sjdp	}
58933965Sjdp      else if (opt (IT_dse_CODE))
59033965Sjdp	{
59133965Sjdp	}
59233965Sjdp      else if (opt (IT_dot_CODE))
59333965Sjdp	{
59433965Sjdp	}
59533965Sjdp      else
59633965Sjdp	break;
59733965Sjdp    }
59833965Sjdp
59933965Sjdp  tab (-1, "");
60033965Sjdp}
60133965Sjdp
60233965Sjdpstatic void
603130561Sobrienmodule (void)
60433965Sjdp{
60533965Sjdp  int c = 0;
60633965Sjdp  int l = 0;
60733965Sjdp
60833965Sjdp  tab (1, "MODULE***\n");
60933965Sjdp
61033965Sjdp  do
61133965Sjdp    {
61233965Sjdp      c = getc (file);
61333965Sjdp      ungetc (c, file);
61433965Sjdp
61533965Sjdp      c &= 0x7f;
61633965Sjdp    }
61733965Sjdp  while (getone (c) && c != IT_tr_CODE);
61833965Sjdp
61933965Sjdp  tab (-1, "");
62033965Sjdp
62133965Sjdp  c = getc (file);
62233965Sjdp  while (c != EOF)
62333965Sjdp    {
62433965Sjdp      printf ("%02x ", c);
62533965Sjdp      l++;
62633965Sjdp      if (l == 32)
62733965Sjdp	{
62833965Sjdp	  printf ("\n");
62933965Sjdp	  l = 0;
63033965Sjdp	}
63133965Sjdp      c = getc (file);
63233965Sjdp    }
63333965Sjdp}
63433965Sjdp
63533965Sjdpchar *program_name;
63633965Sjdp
63733965Sjdpstatic void
638130561Sobrienshow_usage (FILE *file, int status)
63933965Sjdp{
64089857Sobrien  fprintf (file, _("Usage: %s [option(s)] in-file\n"), program_name);
64189857Sobrien  fprintf (file, _("Print a human readable interpretation of a SYSROFF object file\n"));
64289857Sobrien  fprintf (file, _(" The options are:\n\
64389857Sobrien  -h --help        Display this information\n\
64489857Sobrien  -v --version     Print the program's version number\n"));
64589857Sobrien
646218822Sdim  if (REPORT_BUGS_TO[0] && status == 0)
64789857Sobrien    fprintf (file, _("Report bugs to %s\n"), REPORT_BUGS_TO);
64833965Sjdp  exit (status);
64933965Sjdp}
65033965Sjdp
65133965Sjdpint
652130561Sobrienmain (int ac, char **av)
65333965Sjdp{
65433965Sjdp  char *input_file = NULL;
65533965Sjdp  int opt;
65633965Sjdp  static struct option long_options[] =
65733965Sjdp  {
65833965Sjdp    {"help", no_argument, 0, 'h'},
65933965Sjdp    {"version", no_argument, 0, 'V'},
66033965Sjdp    {NULL, no_argument, 0, 0}
66133965Sjdp  };
66233965Sjdp
66360484Sobrien#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
66460484Sobrien  setlocale (LC_MESSAGES, "");
66560484Sobrien#endif
66689857Sobrien#if defined (HAVE_SETLOCALE)
66789857Sobrien  setlocale (LC_CTYPE, "");
66889857Sobrien#endif
66960484Sobrien  bindtextdomain (PACKAGE, LOCALEDIR);
67060484Sobrien  textdomain (PACKAGE);
67160484Sobrien
67233965Sjdp  program_name = av[0];
67333965Sjdp  xmalloc_set_program_name (program_name);
67433965Sjdp
675218822Sdim  expandargv (&ac, &av);
676218822Sdim
67789857Sobrien  while ((opt = getopt_long (ac, av, "HhVv", long_options, (int *) NULL)) != EOF)
67833965Sjdp    {
67933965Sjdp      switch (opt)
68033965Sjdp	{
68189857Sobrien	case 'H':
68233965Sjdp	case 'h':
68389857Sobrien	  show_usage (stdout, 0);
68433965Sjdp	  /*NOTREACHED*/
68589857Sobrien	case 'v':
68633965Sjdp	case 'V':
68789857Sobrien	  print_version ("sysdump");
68833965Sjdp	  exit (0);
68933965Sjdp	  /*NOTREACHED*/
69033965Sjdp	case 0:
69133965Sjdp	  break;
69233965Sjdp	default:
69333965Sjdp	  show_usage (stderr, 1);
69433965Sjdp	  /*NOTREACHED*/
69533965Sjdp	}
69633965Sjdp    }
69733965Sjdp
69833965Sjdp  /* The input and output files may be named on the command line.  */
69933965Sjdp
70033965Sjdp  if (optind < ac)
70189857Sobrien    input_file = av[optind];
70233965Sjdp
70333965Sjdp  if (!input_file)
70489857Sobrien    fatal (_("no input file specified"));
70533965Sjdp
70633965Sjdp  file = fopen (input_file, FOPEN_RB);
70789857Sobrien
70833965Sjdp  if (!file)
70989857Sobrien    fatal (_("cannot open input file %s"), input_file);
71033965Sjdp
71133965Sjdp  module ();
71233965Sjdp  return 0;
71333965Sjdp}
714