/* xdis.c * Disassembler for XCPU. * */ #include #include #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=
specify load address, overriding\n" " default and any specified in file\n" " -D= define a with as its value\n" " -g, --debug include debug information in the object file\n" " -o , --output= 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; }