hexed: Fix some misc. issues
This commit is contained in:
parent
3e10f0084b
commit
b1ef1169b9
@ -10,4 +10,17 @@ menuconfig SYSTEM_HEXED
|
||||
Enable support for the hexed command line hexadecial file editor
|
||||
|
||||
if SYSTEM_HEXED
|
||||
|
||||
config SYSTEM_HEXED_STACKSIZE
|
||||
int "hexed stack size"
|
||||
default 2048
|
||||
---help---
|
||||
The size of stack allocated for the hexed task.
|
||||
|
||||
config SYSTEM_HEXED_PRIORITY
|
||||
int "hexed priority"
|
||||
default 100
|
||||
---help---
|
||||
The priority of the hexed task.
|
||||
|
||||
endif # SYSTEM_HEXED
|
||||
|
@ -43,9 +43,12 @@ endif
|
||||
|
||||
# hexed Application
|
||||
|
||||
CONFIG_SYSTEM_HEXED_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
||||
CONFIG_SYSTEM_HEXED_STACKSIZE ?= 2048
|
||||
|
||||
APPNAME = hexed
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 2048
|
||||
PRIORITY = $(CONFIG_SYSTEM_HEXED_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_SYSTEM_HEXED_STACKSIZE)
|
||||
|
||||
ASRCS =
|
||||
CSRCS = bfile.c cmdargs.c hexcopy.c hexdump.c hexenter.c hexhelp.c
|
||||
|
@ -134,7 +134,7 @@ extern FAR struct bfile_s *g_hexfile;
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
void hexed_error(int eno, FAR const char *fmt, ...);
|
||||
void hexed_fatal(FAR const char *fmt, ...);
|
||||
int hexcopy(FAR struct command_s *cmd, int optc, FAR char *opt);
|
||||
int hexdump(FAR struct command_s *cmd, int optc, FAR char *opt);
|
||||
int hexenter(FAR struct command_s *cmd, int optc, FAR char *opt);
|
||||
@ -143,7 +143,5 @@ int hexinsert(FAR struct command_s *cmd, int optc, FAR char *opt);
|
||||
int hexmove(FAR struct command_s *cmd, int optc, FAR char *opt);
|
||||
int hexremove(FAR struct command_s *cmd, int optc, FAR char *opt);
|
||||
int hexword(FAR struct command_s *cmd, int optc, FAR char *opt);
|
||||
int show_usage(void);
|
||||
void printhex(uint64_t i, int size);
|
||||
|
||||
#endif /* __APPS_SYSTEM_HEXED_INCLUDE_HEXED_H */
|
||||
|
@ -190,6 +190,15 @@ int hexcopy(FAR struct command_s *cmd, int optc, char *opt)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We need to have a file name for this command */
|
||||
|
||||
if (g_hexfile == NULL)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Copy command requires a filename\n");
|
||||
g_last_error = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
optc = runcopy(cmd);
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,38 @@ static int rundump(FAR struct command_s *cmd)
|
||||
|
||||
if (off + x < last)
|
||||
{
|
||||
printhex(*(uint64_t *) (cur + x), cmd->opts.word);
|
||||
/* Print 1-8 byte hexadecimal number */
|
||||
|
||||
switch (cmd->opts.word)
|
||||
{
|
||||
case WORD_64:
|
||||
{
|
||||
uint64_t data = *(uint64_t *)(cur + x);
|
||||
printf("%016llx", (unsigned long long)data);
|
||||
}
|
||||
break;
|
||||
|
||||
case WORD_32:
|
||||
{
|
||||
uint32_t data = *(uint32_t *)(cur + x);
|
||||
printf("%08lx", (unsigned long)data);
|
||||
}
|
||||
break;
|
||||
|
||||
case WORD_16:
|
||||
{
|
||||
uint16_t data = *(uint16_t *)(cur + x);
|
||||
printf("%04x", (unsigned int)data);
|
||||
}
|
||||
break;
|
||||
|
||||
case WORD_8:
|
||||
{
|
||||
uint8_t data = *(uint8_t *)(cur + x);
|
||||
printf("%02x", (unsigned int)data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -211,7 +242,8 @@ int hexdump(FAR struct command_s *cmd, int optc, char *opt)
|
||||
|
||||
if (cmd == NULL || cmd->id != CMD_DUMP)
|
||||
{
|
||||
return -1;
|
||||
g_last_error = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Set/run dump */
|
||||
@ -222,6 +254,15 @@ int hexdump(FAR struct command_s *cmd, int optc, char *opt)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We need to have a file name for this command */
|
||||
|
||||
if (g_hexfile == NULL)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Dump command requires a filename\n");
|
||||
g_last_error = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
optc = rundump(cmd);
|
||||
}
|
||||
|
||||
|
@ -83,40 +83,16 @@ static struct arglist_s g_arglist[] =
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Print hexed_error msg and exit */
|
||||
/* Print error msg and exit */
|
||||
|
||||
void hexed_error(int eno, FAR const char *fmt, ...)
|
||||
void hexed_fatal(FAR const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
va_start(va, fmt);
|
||||
vfprintf(stderr, fmt, va);
|
||||
va_end(va);
|
||||
exit(-eno);
|
||||
}
|
||||
|
||||
/* Print 1-8 byte hexadecimal number */
|
||||
|
||||
void printhex(uint64_t i, int size)
|
||||
{
|
||||
switch (size)
|
||||
{
|
||||
case WORD_64:
|
||||
printf("%016llx", (unsigned long long)i);
|
||||
break;
|
||||
|
||||
case WORD_32:
|
||||
printf("%08lx", (unsigned long)i);
|
||||
break;
|
||||
|
||||
case WORD_16:
|
||||
printf("%04x", (unsigned int)i);
|
||||
break;
|
||||
|
||||
case WORD_8:
|
||||
printf("%02x", (unsigned int)i);
|
||||
break;
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Load a Buffered File hexfile */
|
||||
@ -296,7 +272,7 @@ int parseargs(FAR char *argv[])
|
||||
|
||||
if (strlen(opt) > 1 && *(opt + 1) != '-')
|
||||
{
|
||||
hexed_error(EINVAL, "Unknown option: %s\n", opt);
|
||||
hexed_fatal("ERROR: Unknown option: %s\n", opt);
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,7 +288,7 @@ int parseargs(FAR char *argv[])
|
||||
|
||||
else
|
||||
{
|
||||
hexed_error(EINVAL, "Unexpected option: %s\n", opt);
|
||||
hexed_fatal("ERROR: Unexpected option: %s\n", opt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,8 @@ static int runenter(FAR struct command_s *cmd)
|
||||
static int setenter(FAR struct command_s *cmd, int optc, FAR char *opt)
|
||||
{
|
||||
FAR char *s;
|
||||
int64_t *hx, v;
|
||||
FAR int64_t *hx;
|
||||
int64_t v;
|
||||
|
||||
/* Set defaults */
|
||||
|
||||
@ -109,15 +110,15 @@ static int setenter(FAR struct command_s *cmd, int optc, FAR char *opt)
|
||||
break;
|
||||
|
||||
case WORD_32:
|
||||
*((int32_t *) hx + cmd->opts.cnt) = v;
|
||||
*((int32_t *)hx + cmd->opts.cnt) = v;
|
||||
break;
|
||||
|
||||
case WORD_16:
|
||||
*((int16_t *) hx + cmd->opts.cnt) = v;
|
||||
*((int16_t *)hx + cmd->opts.cnt) = v;
|
||||
break;
|
||||
|
||||
case WORD_8:
|
||||
*((int8_t *) hx + cmd->opts.cnt) = v;
|
||||
*((int8_t *)hx + cmd->opts.cnt) = v;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -133,8 +134,9 @@ static int setenter(FAR struct command_s *cmd, int optc, FAR char *opt)
|
||||
|
||||
else
|
||||
{
|
||||
hexed_error(E2BIG, "Enter error: too many values set\n");
|
||||
fprintf(stderr, "ERROR: too many values set\n");
|
||||
g_last_error = E2BIG;
|
||||
return -E2BIG;
|
||||
}
|
||||
|
||||
return optc;
|
||||
|
@ -157,8 +157,9 @@ static int setinsert(FAR struct command_s *cmd, int optc, char *opt)
|
||||
}
|
||||
else
|
||||
{
|
||||
hexed_error(E2BIG, "Insert error: too many values set\n");
|
||||
fprintf(stderr, "ERROR: Too many values set\n");
|
||||
g_last_error = E2BIG;
|
||||
return -E2BIG;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -222,6 +222,15 @@ int hexmove(FAR struct command_s *cmd, int optc, char *opt)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We need to have a file name for this command */
|
||||
|
||||
if (g_hexfile == NULL)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Move command requires a filename\n");
|
||||
g_last_error = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
optc = runmove(cmd);
|
||||
}
|
||||
|
||||
|
@ -142,6 +142,15 @@ int hexremove(FAR struct command_s *cmd, int optc, char *opt)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We need to have a file name for this command */
|
||||
|
||||
if (g_hexfile == NULL)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Remove command requires a filename\n");
|
||||
g_last_error = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
optc = runremove(cmd);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user