Skip to content

Commit

Permalink
add debug output and fix positional arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
domivogt committed Oct 25, 2016
1 parent 1d38f7a commit 71b8dd6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions fvwm/cmdparser.h
Expand Up @@ -87,6 +87,7 @@ typedef struct
* It is then the responsibility of the caller to free() it. */
void (*release_expanded_line)(cmdparser_context_t *context);
void (*destroy_context)(cmdparser_context_t *context);
void (*debug)(cmdparser_context_t *context, const char *msg);
} cmdparser_hooks_t;

#endif /* CMDPARSER_H */
55 changes: 53 additions & 2 deletions fvwm/cmdparser_old.c
Expand Up @@ -20,7 +20,10 @@
#include "libs/defaults.h"
#include "libs/Parse.h"

#if 1 /*!!!*/
#include <assert.h>
#endif
#include <stdio.h>

#include "cmdparser.h"
#include "cmdparser_old.h"
Expand All @@ -35,6 +38,12 @@

/* ---------------------------- local definitions -------------------------- */

#if 1 /*!!!*/
#define OCP_DEBUG 1
#else
#define OCP_DEBUG 0
#endif

/* ---------------------------- local macros ------------------------------- */

/* ---------------------------- imports ------------------------------------ */
Expand All @@ -51,6 +60,47 @@

/* ---------------------------- local functions ---------------------------- */

static void ocp_debug(cmdparser_context_t *c, const char *msg)
{
int i;

if (!OCP_DEBUG)
{
return;
}
fprintf(stderr, "%s: %p: %s\n", __func__, c, (msg != NULL) ? msg : "");
if (c->is_created == 0)
{
fprintf(stderr, " not created\n");
return;
}
fprintf(stderr, " depth : %d\n", c->call_depth);
fprintf(stderr, " orig line: '%s'\n", c->line ? c->line : "(nil)");
fprintf(stderr, " curr line: '%s'\n", c->cline ? c->cline : "(nil)");
fprintf(
stderr, " exp line: (do_free = %d) '%s'\n",
c->do_free_expline, c->expline ? c->expline : "(nil)");
fprintf(
stderr, " command : '%s'\n",
c->command ? c->command: "(nil)");
if (c->pos_args == NULL)
{
return;
}
fprintf(
stderr, " all args : '%s'\n",
c->pos_args[0] ? c->pos_args[0]: "(nil)");
fprintf(stderr, " pos args :");
for (i = 1; i < CMDPARSER_NUM_POS_ARGS && c->pos_args[i] != NULL; i++)
{
fprintf(stderr, " %d:'%s'", i,
c->pos_args[i] ? c->pos_args[i]: "(nil)");
}
fprintf(stderr, "\n");

return;
}

static int ocp_create_context(
cmdparser_context_t *dest_c, cmdparser_context_t *caller_c, char *line,
char *pos_args[])
Expand Down Expand Up @@ -86,7 +136,7 @@ static int ocp_create_context(
i < CMDPARSER_NUM_POS_ARGS + 1 && pos_args[i] != NULL;
i++)
{
dest_c->pos_args[i - 1] = pos_args[i];
dest_c->pos_args[i] = pos_args[i];
}
}
/*!!!allocate stuff*/
Expand Down Expand Up @@ -247,7 +297,8 @@ static cmdparser_hooks_t old_parser_hooks =
ocp_is_module_config,
ocp_expand_command_line,
ocp_release_expanded_line,
ocp_destroy_context
ocp_destroy_context,
ocp_debug
};

/* ---------------------------- interface functions ------------------------ */
Expand Down
17 changes: 17 additions & 0 deletions fvwm/functions.c
Expand Up @@ -376,6 +376,9 @@ static void __execute_command_line(
Window dummy_w;
int rc;

#if 1 /*!!!*/
fprintf(stderr, "%s: cpc %p, xaction '%s'\n", __func__, caller_pc, xaction);
#endif
set_silent = 0;
/* generate a parsing context; this *must* be destroyed before
* returning */
Expand All @@ -384,11 +387,13 @@ static void __execute_command_line(
{
goto fn_exit;
}
cmdparser_hooks->debug(&pc, "!!!A");
rc = cmdparser_hooks->handle_line_start(&pc);
if (rc != 0)
{
goto fn_exit;
}
cmdparser_hooks->debug(&pc, "!!!B");

{
cmdparser_prefix_flags_t flags;
Expand Down Expand Up @@ -416,6 +421,7 @@ static void __execute_command_line(
}
err_cline = pc.cline;
}
cmdparser_hooks->debug(&pc, "!!!C");

if (exc->w.fw == NULL || IS_EWMH_DESKTOP(FW_W(exc->w.fw)))
{
Expand Down Expand Up @@ -467,11 +473,13 @@ static void __execute_command_line(
func = cmdparser_hooks->parse_command_name(&pc, func_rc, exc);
if (func != NULL)
{
cmdparser_hooks->debug(&pc, "!!!D");
bif = find_builtin_function(func);
err_func = func;
}
else
{
cmdparser_hooks->debug(&pc, "!!!E");
bif = NULL;
err_func = "";
}
Expand All @@ -491,6 +499,7 @@ static void __execute_command_line(
expaction = cmdparser_hooks->expand_command_line(
&pc, (bif) ? !!(bif->flags & FUNC_ADD_TO) : False,
func_rc, exc);
cmdparser_hooks->debug(&pc, "!!!F");
if (pc.call_depth <= 1)
{
int did_store_string;
Expand All @@ -500,13 +509,18 @@ static void __execute_command_line(
if (did_store_string == 1)
{
cmdparser_hooks->release_expanded_line(&pc);
cmdparser_hooks->debug(&pc, "!!!G");
}
}
}
else
{
cmdparser_hooks->debug(&pc, "!!!H");
expaction = pc.cline;
}
#if 1 /*!!!*/
fprintf(stderr, "!!!expcation: '%s'\n", expaction);
#endif

#ifdef FVWM_COMMAND_LOG
fvwm_msg(INFO, "LOG", "%c: %s", (char)exc->type, expaction);
Expand All @@ -517,6 +531,7 @@ static void __execute_command_line(
* the asterisk. */
if (cmdparser_hooks->is_module_config(&pc) == 1)
{
cmdparser_hooks->debug(&pc, "!!!I");
if (Scr.cur_decor && Scr.cur_decor != &Scr.DefaultDecor)
{
fvwm_msg(
Expand All @@ -534,6 +549,7 @@ static void __execute_command_line(
exec_context_changes_t ecc;
exec_context_change_mask_t mask;

cmdparser_hooks->debug(&pc, "!!!J");
mask = (w != exc->w.w) ? ECC_W : 0;
ecc.w.fw = exc->w.fw;
ecc.w.w = w;
Expand Down Expand Up @@ -561,6 +577,7 @@ static void __execute_command_line(
* skip command */
rc = 1;
}
fprintf(stderr, "!!!runaction: '%s'\n", runaction);
if (rc == 0)
{
exc2 = exc_clone_context(exc, &ecc, mask);
Expand Down

0 comments on commit 71b8dd6

Please sign in to comment.