Quelltext /~heha/hs/gputils64-210929.zip/gputils/gpvc.cpp

/* Displays contents of ".COD" files
   Copyright 2001-2005	Scott Dattalo
   Copyright 2016	Molnár Károly
*/

#include "stdhdr.h"

#include "libgputils.h"
#include "gpvc.h"
#include "dump.h"
#include "block.h"
enum{
  DISPLAY_NOTHING = 0,
  DISPLAY_DIR	= 1<<0,
  DISPLAY_SYM	= 1<<1,
  DISPLAY_ROM	= 1<<2,
  DISPLAY_SRC	= 1<<3,
  DISPLAY_MESS	= 1<<4,
  DISPLAY_ALL	= DISPLAY_DIR|DISPLAY_SYM|DISPLAY_ROM|DISPLAY_SRC|DISPLAY_MESS,
  DISPLAY_WIDE	= 1<<5,
};

static const char longopts[] =
  "aall\0"
  "ddirectory\0"
  "llisting\0"
  "mmessage\0"
  "hhelp\0"
  "rrom\0"
  "ssymbols\0"
  "vversion\0"
  "wwide\0";

static const char longdesc[] =
  "Display all information in .cod file.\0"
  "Display directory header.\0"
  "Display source listing.\0"
  "Display debug message area.\0"
  "Show this usage message.\0"
  "Display rom.\0"
  "Display symbols.\0"
  "Show version.\0"
  "Show code table in wider view.\0";

static FILE         *code_file;
static DirBlockInfo *main_dir;

/*------------------------------------------------------------------------------------------------*/

static void _show_usage(const char*argv0) {
  gp_usage(argv0,longopts,longdesc,20);
  exit(0);
}

/*------------------------------------------------------------------------------------------------*/
static bool usage;
static char display_flags;
static const char*file_name;

static void _stdcall onOption(void*,char c, const char*arg) {
  switch (c) {
    case '?':
    case 'h': usage = true;			break;
    case 'a': display_flags |= DISPLAY_ALL;	break;
    case 'd': display_flags |= DISPLAY_DIR;	break;
    case 's': display_flags |= DISPLAY_SYM;	break;
    case 'r': display_flags |= DISPLAY_ROM;	break;
    case 'l': display_flags |= DISPLAY_SRC;	break;
    case 'm': display_flags |= DISPLAY_MESS;	break;
    case 'w': display_flags |= DISPLAY_WIDE;	break;
    case 'v':
      fprintf(stderr, "%s\n", GPVC_VERSION_STRING);
      exit(0);
    case 0: file_name = arg;			break;
  }
}

int main(int argc, char *argv[]) {
  char            processor_name[COD_DIR_PROCESSOR_LENGTH + 1];
  pic_processor_t processor_info;
  proc_class_t    processor_class;

  gp_init();

  gp_getopt(argv,longopts,onOption);

  if (!display_flags) display_flags = DISPLAY_ALL;

  if (!file_name || usage) {
    _show_usage(*argv);
  }

  code_file = fopen(file_name, "rb");
  if (code_file == NULL) {
    perror(file_name);
    exit(1);
  }

  /* Start off by reading the directory block. */
  main_dir = read_directory(code_file);

  /* Determine if byte address and org are different. */
  gp_str_from_Pstr(processor_name, sizeof(processor_name),
                   &main_dir->dir[COD_DIR_PROCESSOR], COD_DIR_PROCESSOR_SIZE, NULL);

  processor_info  = gp_find_processor(processor_name);
  assert(processor_info);
  processor_class = gp_processor_class(processor_info);

  if (display_flags & DISPLAY_DIR) {
    dump_directory_blocks(main_dir, processor_class);
  }

  if (display_flags & DISPLAY_ROM) {
    dump_code(code_file, main_dir, processor_info, (bool)!!(display_flags & DISPLAY_WIDE));
  }

  if (display_flags & DISPLAY_SYM) {
    dump_symbols(code_file, main_dir);
    dump_lsymbols(code_file, main_dir);
    dump_local_vars(code_file, main_dir, processor_class);
  }

  dump_source_files(code_file, main_dir);

  if (display_flags & DISPLAY_SRC) {
    dump_line_symbols(code_file, main_dir);
  }

  if (display_flags & DISPLAY_MESS) {
    dump_debug_message_area(code_file, main_dir);
  }

  fclose(code_file);
  dump_free();
  return EXIT_SUCCESS;
}
Vorgefundene Kodierung: UTF-80