Skip to content

Commit

Permalink
GH-34 Fix p4System() handling of ctx->input WRT changes made to
Browse files Browse the repository at this point in the history
`P4_Ctx.input` and `P4_Input` in commit 215bc11.
  • Loading branch information
SirWumpus committed Sep 9, 2024
1 parent bc6650e commit cb849fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@

#ifdef HAVE_HOOKS

# ifdef USE_HOOK_SHELL
# ifdef HOOK_SHELL
/*
* SH ( `input` -- )
* SH ( `remaining input line` -- )
*/
static void
p4System(P4_Ctx *ctx)
{
P4_Input *input = ctx->input;
// Assumes input buffer is writeable.
ctx->input.buffer[ctx->input.length < ctx->input.size ? ctx->input.length : ctx->input.size-1] = '\0';
(void) system(ctx->input.buffer + ctx->input.offset);
ctx->input.offset = ctx->input.length;
input->buffer[input->length] = '\0';
(void) system(input->buffer + input->offset);
input->offset = input->length;
}

/*
Expand All @@ -34,7 +35,7 @@ p4SystemString(P4_Ctx *ctx)
}
# endif

# ifdef USE_HOOK_PRIMATIVES
# ifdef HOOK_PRIMATIVES
/* Examples of how some words, in particular those calling libc
* or other library functions can be isolated as hooks.
*/
Expand Down Expand Up @@ -79,11 +80,11 @@ p4TimeDate(P4_Ctx *ctx)
# endif

static P4_Hook p4_hooks[] = {
# ifdef USE_HOOK_SHELL
# ifdef HOOK_SHELL
{ "SH", p4System },
{ "SHELL", p4SystemString },
# endif
# ifdef USE_HOOK_PRIMATIVES
# ifdef HOOK_PRIMATIVES
{ "MOVE", p4Move },
{ "TIME&DATE", p4STimeDate },
# endif
Expand Down
4 changes: 4 additions & 0 deletions src/post4.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ extern "C" {
#define ASSERT_LINE_BUFFERING 1
#endif

#ifdef HAVE_HOOKS
#define HOOK_SHELL 1
#endif

/***********************************************************************
*** No configuration below this point.
***********************************************************************/
Expand Down

0 comments on commit cb849fb

Please sign in to comment.