irom static app_action_t application_function_display_dump(application_parameters_t ap)
{
	int8_t verbose;

	if(ap.nargs > 1)
		verbose = (uint8_t)atoi((*ap.args)[1]);
	else
		verbose = 0;

	display_dump(ap.size, ap.dst, verbose);

	return(app_action_normal);
}
Пример #2
0
/*
 * ---------------------------------------------------------------------------
 *  main
 *      Entry point for the unifi_coredump program
 *
 *  Arguments:
 *      argc, argv
 *
 *  Returns:
 *      0 on success, non-zero on error
 *
 *  Notes:
 * ---------------------------------------------------------------------------
 */
int
main(int argc, char *argv[])
{
    char device[32];
    int start = 0;
    int index = -2;
    int list = 0;
    int force = 0;
    int force_reset = 0;
    int debug_level = -1;
    int r = 0;
    int fd = -1;
    int option_index = 0;
    int optc;

    static const struct option long_options[] = {
               {"dev",      1, 0, 0},
               {"force",    0, 0, 0},
               {"reset",    0, 0, 0},
               {"verbose",  0, 0, 0},
               {"brief",    0, 0, 0},
               {"list",     0, 0, 0},
               {"index",    1, 0, 0},
               {"debug",    1, 0, 0},
               {0,          0, 0, 0} };

    strcpy(&device[0], "/dev/unifiudi0");       /* Default device */

    if (argc > 1) {
        if (!strcasecmp(argv[1], "--help")) {
            print_usage();
            r = 1;
            goto EXIT;
        }
    }

    while ((optc = getopt_long(argc, argv, "", long_options, &option_index)) != -1) {
        start = 1;
        if (optc == 0) {

            if (!strcasecmp(long_options[option_index].name, "dev")) {
                r = strlen(optarg);
                if (r >= (sizeof(device) - 1)) {
                    fprintf(stderr, "dev arg %s is too long\n", optarg);
                    r = 1;
                    goto EXIT;
                }
                memcpy(device, optarg, r);
                device[r] = 0;
                continue;
            }

            if (!strcasecmp(long_options[option_index].name, "verbose")) {
                verbose++;
                continue;
            }

            if (!strcasecmp(long_options[option_index].name, "force")) {
                if (verbose) {
                    printf("Triggering coredump on UniFi\n");
                }
                force = 1;
                continue;
            }

            if (!strcasecmp(long_options[option_index].name, "reset")) {
                if (verbose) {
                    printf("Triggering simulated reset on UniFi\n");
                }
                force = 1;
                force_reset = 1;
                continue;
            }

            if (!strcasecmp(long_options[option_index].name, "list")) {
                list = 1;
                if (verbose) {
                    printf("list specified\n");
                }
                continue;
            }

            if (!strcasecmp(long_options[option_index].name, "brief")) {
                if (verbose) {
                    printf("Using shortened format\n");
                }
                brief = 1;
                continue;
            }

            if (!strcasecmp(long_options[option_index].name, "index")) {
                if (optarg == NULL) {
                    fprintf(stderr, "option 'index' requires an argument\n");
                    r = 1;
                    goto EXIT;
                }

                index = atoi(optarg);
                if (verbose) {
                    fprintf(stderr, "index %d specified\n", index);
                }
                continue;
            }

            if (!strcasecmp(long_options[option_index].name, "debug")) {
                if (optarg == NULL) {
                    fprintf(stderr, "option 'debug' requires an argument\n");
                    r = 1;
                    goto EXIT;
                }

                debug_level = atoi(optarg);
                if (verbose) {
                    fprintf(stderr, "driver debug level %d specified\n", debug_level);
                }
                continue;
            }

            fprintf(stderr, "Unrecognised option: %s\n", long_options[option_index].name);
            start = 0;
            break;

        } else {
            start = 0;
        }
    }

    if (optind < argc) {
        printf("Unrecognised option(s) ignored: ");
        while (optind < argc) {
            fprintf(stderr, "%s ", argv[optind++]);
        }
        fprintf (stderr, "\n");
    }

    if (start == 0) {
        print_usage();
        r = 1;
        goto EXIT;
    }

    if (verbose) {
        fprintf(stderr, "Using:\n");
        fprintf(stderr, " DEVICE    : %s\n", device);
        fprintf(stderr, " Verbosity : %d\n", verbose);
        fprintf(stderr, "\n");
    }

    /*
     * Act on commands
     */
    fd = open(device, O_RDWR);
    if (fd < 0) {
        fprintf(stderr, "%d - ", errno);
        perror("Failed to open device");
        r = errno;
        goto EXIT;
    } else if (verbose) {
        fprintf(stderr, "Opened %s sucessfully\n", device);
    }

    if (force) {
        r = force_coredump(fd, force_reset);
        if (r < 0) {
            goto EXIT;
        }
    }

    if (list) {
        r = display_list(fd);
        if (r < 0) {
            goto EXIT;
        }
    }

    if (index >= -1) {
        r = display_dump(fd, index);
        if (r < 0) {
            goto EXIT;
        }
    }

    if (debug_level >= 0) {
        r = set_driver_debug(fd, debug_level);
        if (r < 0) {
            goto EXIT;
        }
    }

EXIT:
    if (fd >= 0) {
        close(fd);
    }

    if (verbose) {
        fprintf(stderr, "Exit (%d)\n", r);
    }

    return r;
} /* main() */
Пример #3
0
/**
 * Hack -- change name
 */
void do_cmd_change_name(void)
{
  ui_event ke;
  
  int col = 0;
  int last_line = 0;
  int top_line = 0;

  const char *p;

  /* Prompt */
  p = "['c' change name, 'f' to file, scroll, or ESC]";
  
  /* Save screen */
  screen_save();

  /* Adjust the buttons */
  button_backup_all();
  button_kill_all();
  button_add("ESC", ESCAPE);
  button_add("Spc", ' ');
  button_add("-", '-');
  button_add("c", 'c');
  button_add("f", 'f');
  button_add("->", ARROW_RIGHT);
  button_add("<-", ARROW_LEFT);
  p_ptr->redraw |= PR_BUTTONS;

  /* Make the array of lines */
  C_WIPE(dumpline, DUMP_MAX_LINES, char_attr_line);
  last_line = make_dump(dumpline, 2);

  /* Forever */
  while (1)
    {
      /* Display the player */
      display_dump(dumpline, top_line, top_line + Term->hgt - 1, col);

      redraw_stuff(p_ptr);

      /* Clear the bottom line */
      prt("", Term->hgt - 1, 0);
      
      /* Prompt */
      Term_putstr(0, Term->hgt - 1, -1, TERM_WHITE, p);
     
      /* Query */
      ke = inkey_ex();
      
      /* Exit */
      if (ke.key.code == ESCAPE) break;
      
      /* Change name */
      if (ke.key.code == 'c')
        {
	  char namebuf[32] = "";

	  if (get_name(namebuf, sizeof namebuf))
	  {
	      /* Set player name */
	      my_strcpy(op_ptr->full_name, namebuf,
			sizeof(op_ptr->full_name));
	      
	      /* Don't change savefile name. */
	      process_player_name(FALSE);
	  }
	  //(void) get_name(namebuf, sizeof namebuf);
	  (void) make_dump(dumpline, 2);
        }
      
      /* File dump */
      else if (ke.key.code == 'f')
	{
	  char ftmp[80];
	  
	  strnfmt(ftmp, sizeof ftmp, "%s.txt", op_ptr->base_name);
	  
	  if (get_string("File name: ", ftmp, 80))
	    {
	      if (ftmp[0] && (ftmp[0] != ' '))
		{
		  if (file_character(ftmp, dumpline, last_line))
		    msg("Character dump failed!");
		  else
		    msg("Character dump successful.");
		}
	    }
	}
      
      /* Scroll down */
      else if (ke.key.code == ARROW_DOWN)
	{
	  if (top_line + Term->hgt - 2 < last_line)
	    top_line++;
	}
      
      /* Page down */
      else if (ke.key.code == ' ')
	{
	  top_line = MIN(last_line - Term->hgt + 2, 
			 top_line + (Term->hgt - 2));
	}
      
      /* Scroll up */
      else if (ke.key.code == ARROW_UP)
	{
	  if (top_line)
	    top_line--;
	}
      
      /* Page up */
      else if (ke.key.code == '-')
	{
	  top_line -= (Term->hgt - 2) / 2;
	  if (top_line < 0) top_line = 0;
	}
      
      /* Scroll left */
      else if (ke.key.code == ARROW_LEFT)
	{
	  if (col)
	    col--;
	}
      
      /* Scroll right */
      else if (ke.key.code == ARROW_RIGHT)
	{
	  if (col < 32)
	    col++;
	}
      
      
      /* Oops */
      else
	{
	  bell(NULL);
	}
      
      /* Flush messages */
      message_flush();
    }

  /* Adjust the buttons */
  button_restore();

  /* Load screen */
  screen_load();
}