--- mon/src/mon.cpp 2000/04/24 13:10:00 1.6 +++ mon/src/mon.cpp 2000/10/15 15:07:12 1.14 @@ -1,7 +1,7 @@ /* - * mon.cpp - mon main program + * mon.cpp - cxmon main program * - * mon (C) 1997-2000 Christian Bauer, Marc Hellwig + * cxmon (C) 1997-2000 Christian Bauer, Marc Hellwig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,13 +25,21 @@ #include #include -#ifdef HAVE_READLINE_READLINE_H +#if defined(HAVE_READLINE_H) +extern "C" { +#include +} +#elif defined(HAVE_READLINE_READLINE_H) extern "C" { #include } #endif -#ifdef HAVE_READLINE_HISTORY_H +#if defined(HAVE_HISTORY_H) +extern "C" { +#include +} +#elif defined(HAVE_READLINE_HISTORY_H) extern "C" { #include } @@ -40,6 +48,10 @@ extern "C" { #include "mon.h" #include "mon_cmd.h" +#ifndef VERSION +#define VERSION "2" +#endif + // Buffer we're operating on bool mon_use_real_mem = false; @@ -1056,38 +1068,39 @@ void mon_init(void) num_cmds = 0; cmd_help = NULL; - mon_add_command("??", mon_cmd_list, "?? Show list of commands\n"); - mon_add_command("ver", version, "ver Show version\n"); - mon_add_command("?", print_expr, "? expression Calculate expression\n"); - mon_add_command("@", reallocate, "@ [size] Reallocate buffer\n"); - mon_add_command("i", ascii_dump, "i [start [end]] ASCII memory dump\n"); - mon_add_command("m", memory_dump, "m [start [end]] Hex/ASCII memory dump\n"); - mon_add_command("b", binary_dump, "b [start [end]] Binary memory dump\n"); - mon_add_command("d", disassemble_ppc, "d [start [end]] Disassemble PowerPC code\n"); - mon_add_command("d65", disassemble_6502, "d65 [start [end]] Disassemble 6502 code\n"); - mon_add_command("d68", disassemble_680x0, "d68 [start [end]] Disassemble 680x0 code\n"); - mon_add_command("d80", disassemble_8080, "d80 [start [end]] Disassemble 8080 code\n"); - mon_add_command("d86", disassemble_80x86, "d86 [start [end]] Disassemble 80x86 code\n"); - mon_add_command(":", modify, ": start string Modify memory\n"); - mon_add_command("f", fill, "f start end string Fill memory\n"); - mon_add_command("y", apply_byte, "y[b|h|w] start end expr Apply expression to memory\n"); + mon_add_command("??", mon_cmd_list, "?? Show list of commands\n"); + mon_add_command("ver", version, "ver Show version\n"); + mon_add_command("?", print_expr, "? expression Calculate expression\n"); + mon_add_command("@", reallocate, "@ [size] Reallocate buffer\n"); + mon_add_command("i", ascii_dump, "i [start [end]] ASCII memory dump\n"); + mon_add_command("m", memory_dump, "m [start [end]] Hex/ASCII memory dump\n"); + mon_add_command("b", binary_dump, "b [start [end]] Binary memory dump\n"); + mon_add_command("d", disassemble_ppc, "d [start [end]] Disassemble PowerPC code\n"); + mon_add_command("d65", disassemble_6502, "d65 [start [end]] Disassemble 6502 code\n"); + mon_add_command("d68", disassemble_680x0, "d68 [start [end]] Disassemble 680x0 code\n"); + mon_add_command("d80", disassemble_z80, "d80 [start [end]] Disassemble Z80 code\n"); + mon_add_command("d86", disassemble_80x86_32, "d86 [start [end]] Disassemble 80x86 (32-bit) code\n"); + mon_add_command("d8086", disassemble_80x86_16, "d8086 [start [end]] Disassemble 80x86 (16-bit) code\n"); + mon_add_command(":", modify, ": start string Modify memory\n"); + mon_add_command("f", fill, "f start end string Fill memory\n"); + mon_add_command("y", apply_byte, "y[b|h|w] start end expr Apply expression to memory\n"); mon_add_command("yb", apply_byte, NULL); mon_add_command("yh", apply_half, NULL); mon_add_command("yw", apply_word, NULL); - mon_add_command("t", transfer, "t start end dest Transfer memory\n"); - mon_add_command("c", compare, "c start end dest Compare memory\n"); - mon_add_command("h", help_or_hunt, "h start end string Search for byte string\n"); - mon_add_command("\\", shell_command, "\\ \"command\" Execute shell command\n"); - mon_add_command("ls", mon_exec, "ls [args] List directory contents\n"); - mon_add_command("rm", mon_exec, "rm [args] Remove file(s)\n"); - mon_add_command("cp", mon_exec, "cp [args] Copy file(s)\n"); - mon_add_command("mv", mon_exec, "mv [args] Move file(s)\n"); - mon_add_command("cd", mon_change_dir, "cd directory Change current directory\n"); - mon_add_command("o", redir_output, "o [\"file\"] Redirect output\n"); - mon_add_command("[", load_data, "[ start \"file\" Load data from file\n"); - mon_add_command("]", save_data, "] start size \"file\" Save data to file\n"); - mon_add_command("set", set_var, "set [var[=value]] Set/clear/show variables\n"); - mon_add_command("cv", clear_vars, "cv Clear all variables\n"); + mon_add_command("t", transfer, "t start end dest Transfer memory\n"); + mon_add_command("c", compare, "c start end dest Compare memory\n"); + mon_add_command("h", help_or_hunt, "h start end string Search for byte string\n"); + mon_add_command("\\", shell_command, "\\ \"command\" Execute shell command\n"); + mon_add_command("ls", mon_exec, "ls [args] List directory contents\n"); + mon_add_command("rm", mon_exec, "rm [args] Remove file(s)\n"); + mon_add_command("cp", mon_exec, "cp [args] Copy file(s)\n"); + mon_add_command("mv", mon_exec, "mv [args] Move file(s)\n"); + mon_add_command("cd", mon_change_dir, "cd directory Change current directory\n"); + mon_add_command("o", redir_output, "o [\"file\"] Redirect output\n"); + mon_add_command("[", load_data, "[ start \"file\" Load data from file\n"); + mon_add_command("]", save_data, "] start size \"file\" Save data to file\n"); + mon_add_command("set", set_var, "set [var[=value]] Set/clear/show variables\n"); + mon_add_command("cv", clear_vars, "cv Clear all variables\n"); mon_read_byte = NULL; mon_write_byte = NULL; @@ -1121,20 +1134,23 @@ void mon(int argc, char **argv) monout = stdout; monerr = stdout; - if (argc) { - // Access real memory if mon was started as "rmon" - char *prgname = argv[0]; - char *lastslash; - if ((lastslash = strrchr(prgname, '/')) != NULL) - prgname = lastslash + 1; - if (strcmp(prgname, "rmon") == 0) + // Make argc/argv point to the actual arguments + if (argc) + argc--; argv++; + + // Parse arguments + mon_macos_mode = false; + mon_use_real_mem = false; + while (argc > 0) { + if (strcmp(argv[0], "-m") == 0) + mon_macos_mode = true; + else if (strcmp(argv[0], "-r") == 0) mon_use_real_mem = true; - - // Make argc/argv point to the actual arguments - argc--; - argv++; - interactive = (argc == 0); + else + break; + argc--; argv++; } + interactive = (argc == 0); // Set up memory access functions if not supplied by the user if (mon_read_byte == NULL) { @@ -1157,8 +1173,8 @@ void mon(int argc, char **argv) // Print banner if (interactive) - fprintf(monerr, "\n *** mon V" VERSION " by Christian Bauer and Marc Hellwig ***\n" - " *** Press 'h' for help ***\n\n"); + fprintf(monerr, "\n *** cxmon V" VERSION " by Christian Bauer and Marc Hellwig ***\n" + " *** Press 'h' for help ***\n\n"); } init_abort();