aboutsummaryrefslogtreecommitdiff
path: root/xcpu/xdis.c
blob: 22882bb8d9d7ac5018b1705841aa4424bdf9a104 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* xdis.c
 * Disassembler for XCPU.
 *
 */

#include <stdio.h>
#include <getopt.h>

#define PROGRAM_NAME "XAS"
#define VERSION "0.9"
#define AUTHOR "Jonathan duSaint"
#define AUTHOR_EMAIL "jon@rockgeeks.net"

char pname[];
char version[];
char author[];
char author_email[];


void
print_version (void)
{
  printf ("%s %s\n"
	  "Copyright (C) 2006 %s <%s>\n"
	  "%s is free software under the terms of the GNU General Public\n"
	  "License version 2; see the file COPYING in the source\n"
	  "distribution for details.  This software comes with ABSOLUTELY\n"
	  "NO WARRANTY.\n",
	  pname, version, author, author_email, pname);
}

void
help (void)
{
  printf (
"Usage: xas [options] file\n"
"Assembler for XCPU\n"
"\n"
"Options:\n"
"  -h, --help       display this help and exit\n"
"  -v, --version    output version information and exit\n"
"  -V, --verbose    print status information while running\n"
"  -L, --LOUD       print even more information - probably only useful\n"
"                     for debugging XAS\n"
"  -a<address>, --address=<address>  specify load address, overriding\n"
"                                      default and any specified in file\n"
"  -D<macro>=<val>  define a <macro> with <val> as its value\n"
"  -g, --debug      include debug information in the object file\n"
"  -o <file>, --output=<file>  specify name of output file\n");
}


int
main (int argc, char *argv[])
{
  struct option options[] = {
    { "output", required_argument, NULL, 'o' },
    { "help", no_argument, NULL, 'h' },
    { "version", no_argument, NULL, 'v' },
    { 0, 0, 0, 0 },
  };

  opterr = 0;

  while (1)
    {
      opt = getopt_long (argc, argv, "o:hv", options, &index);

      if (opt == EOF) break;

      switch (opt)
	{
	case 'o':
	  output_file = xmalloc (strlen (optarg) + 1);
	  strcpy (output_file, optarg);
	  break;
	case 'h':
	  help ();
	  return 0;
	case 'v':
	  print_version ();
	  return 0;
	case ':':
	  fprintf (stderr, "%s: GETOPT internal error\n", pname);
	  exit (1);
	case '?':
	  fprintf (stderr, "%s: unknown option character `%c'\n",
		   pname, optopt);
	  break;
	default:
	  fprintf (stderr, "%s: ?? getopt returned character code 0x%x ??\n",
		   pname, opt);
	}
    }

  input_file = argv[optind];

  if (output_file == NULL)
    {
      size_t nchar = strlen (input_file);

      output_file = xmalloc (nchar + 3);
      if (input_file[nchar-2] == '.' && input_file[nchar-1] == 's') nchar -= 2;

      strncpy (output_file, input_file, nchar);
      strcat (output_file, ".s");
    }




  xfree (output_file);
  free_all ();

  return 0;
}