Skip to content

Commit

Permalink
Convert special logic in __execute_command_line for functions ...
Browse files Browse the repository at this point in the history
... that may move a window to a separate function flag.

Move find_builtin_function() to functable.[ch].

Moved some functions to functable.[ch] and functable_complex.[ch].

This separation is needed for the parsing hooks.  It was very difficult to get
the #icludes right.  The DesktopsInfo structure was moved to libs/FScreen.h
so that the library does not depend on core header files anymore.

Move WindowConditionMask from mvwm.h to conditional.h.

Finish 1st draft of hook implementation (__execute_command_line)
  • Loading branch information
domivogt committed Oct 25, 2016
1 parent 4deefa9 commit 7f35780
Show file tree
Hide file tree
Showing 16 changed files with 782 additions and 486 deletions.
4 changes: 2 additions & 2 deletions fvwm/Makefile.am
Expand Up @@ -19,7 +19,7 @@ fvwm_SOURCES = \
placement.h read.h repeat.h execcontext.h schedule.h screen.h \
session.h stack.h style.h update.h virtual.h window_flags.h frame.h \
infostore.h \
cmdparser.h cmdparser_old.h \
cmdparser.h cmdparser_hooks.h cmdparser_old.h functable_complex.h \
\
menus.c style.c borders.c events.c move_resize.c builtins.c \
add_window.c icons.c fvwm.c frame.c placement.c virtual.c \
Expand All @@ -30,7 +30,7 @@ fvwm_SOURCES = \
cursor.c colormaps.c modconf.c ewmh_conf.c read.c schedule.c \
menucmd.c ewmh_names.c icccm2.c windowshade.c focus_policy.c repeat.c \
execcontext.c menugeometry.c menudim.c condrc.c infostore.c \
cmdparser_old.c
cmdparser_old.c functable_complex.c

fvwm_DEPENDENCIES = $(top_builddir)/libs/libfvwm.a

Expand Down
64 changes: 17 additions & 47 deletions fvwm/cmdparser.h
Expand Up @@ -7,12 +7,14 @@

/* ---------------------------- global definitions ------------------------- */

/* $0 through to $9 */
#define CMDPARSER_NUM_POS_ARGS 10

/* ---------------------------- global macros ------------------------------ */

/* ---------------------------- type definitions --------------------------- */

/* Enum for all the possible prefixes. */
typedef enum
{
CP_PREFIX_NONE = 0,
Expand All @@ -21,73 +23,41 @@ typedef enum
CP_PREFIX_KEEPRC = 0x4
} cmdparser_prefix_flags_t;

/* Enum for types of things to execute. */
typedef enum
{
CP_EXECTYPE_UNKNOWN = 0,
CP_EXECTYPE_BUILTIN_FUNCTION,
CP_EXECTYPE_COMPLEX_FUNCTION,
CP_EXECTYPE_COMPLEX_FUNCTION_DOES_NOT_EXIST,
CP_EXECTYPE_MODULECONFIG
} cmdparser_execute_type_t;

/* move this to the implementation file and use void* instead??? */

typedef struct
{
/* !!!note: need to define which bits in here may be accessed by the
* user and which are internal */
char is_created : 1;
unsigned char is_created : 1;
/* the original command line */
char *line;
/* the current command line */
char *cline;
/* the expanded command line */
char *expline;
int do_free_expline : 1;
unsigned char do_free_expline : 1;
/* the command name */
char *command;
/* name of the complex function if present */
char *complex_function_name;
/* current function nesting depth */
int call_depth;
/* an array of positional arguments; the first array element contains
* a string with all positional arguments, the remaining ten array
* elements contain the first ten positional arguments. Any of this
* may be NULL pointers */
char *pos_args[CMDPARSER_NUM_POS_ARGS];
char *pos_args[CMDPARSER_NUM_POS_ARGS + 1];
} cmdparser_context_t;

typedef struct
{
/* in general, functions in this structure that return int return
* 0: success
* > 0: unsuccessful but not an error condition
* < 0: unsuccessful, error
*/
int (*create_context)(
/* context structure to initialise */
cmdparser_context_t *dest_context,
/* context structure of the caller or NULL */
cmdparser_context_t *caller_context,
/* input command line */
char *line,
/* an array of positional arguments or NULL; the first array
* element contains a string with all positional arguments,
* the remaining ten array elements contain the first ten
* positional arguments, up to the first NULL pointer; may be
* NULL if not present */
char *pos_args[]
);
int (*handle_line_start)(cmdparser_context_t *context);
/* Returns a set of or'ed flags of which prefixes are present on the
* command line. The prefixes are stripped. */
cmdparser_prefix_flags_t (*handle_line_prefix)(
cmdparser_context_t *context);
/* parses and returns the command name or returns a NULL pointer if not
* possible */
const char *(*parse_command_name)(
cmdparser_context_t *context, void *func_rc, const void *exc);
/* returns 1 if the stored command is a module configuration command
* and 0 otherwise */
int (*is_module_config)(cmdparser_context_t *context);
/* returns the expanded command line */
char *(*expand_command_line)(
cmdparser_context_t *context, int is_addto, void *func_rc,
const void *exc);
/* Release the expline field from the context structure and return it.
* 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 */
72 changes: 72 additions & 0 deletions fvwm/cmdparser_hooks.h
@@ -0,0 +1,72 @@
/* -*-c-*- */

#ifndef CMDPARSER_HOOKS_H
#define CMDPARSER_HOOKS_H

/* ---------------------------- included header files ---------------------- */

/* ---------------------------- global definitions ------------------------- */

/* ---------------------------- global macros ------------------------------ */

/* ---------------------------- type definitions --------------------------- */

typedef struct
{
/* in general, functions in this structure that return int return
* 0: success
* > 0: unsuccessful but not an error condition
* < 0: unsuccessful, error
*/
int (*create_context)(
/* context structure to initialise */
cmdparser_context_t *dest_context,
/* context structure of the caller or NULL */
cmdparser_context_t *caller_context,
/* input command line */
char *line,
/* an array of positional arguments or NULL; the first array
* element contains a string with all positional arguments,
* the remaining ten array elements contain the first ten
* positional arguments, up to the first NULL pointer; may be
* NULL if not present */
char *pos_args[]
);
int (*handle_line_start)(cmdparser_context_t *context);
/* Returns a set of or'ed flags of which prefixes are present on the
* command line. The prefixes are stripped. */
cmdparser_prefix_flags_t (*handle_line_prefix)(
cmdparser_context_t *context);
/* parses and returns the command name or returns a NULL pointer if not
* possible */
const char *(*parse_command_name)(
cmdparser_context_t *context, void *func_rc, const void *exc);
/* returns 1 if the stored command is a module configuration command
* and 0 otherwise */
int (*is_module_config)(cmdparser_context_t *context);
/* expandeds the command line */
void (*expand_command_line)(
cmdparser_context_t *context, int is_addto, void *func_rc,
const void *exc);
/* Release the expline field from the context structure and return it.
* It is then the responsibility of the caller to free() it. */
void (*release_expanded_line)(cmdparser_context_t *context);
/* Tries to find a builtin function, a complex function or a module
* config line to execute and returns the type found or
* CP_EXECTYPE_UNKNOWN if none of the above was identified. For a
* builtin or a complex funtion the pointer to the description is
* returned in *ret_builtin or *ret_complex_function. Consumes the
* the "Module" or the "Function" command form the input. Dos not
* consider builtin functions if *ret_builtin is != NULL when the
* function is called. */
cmdparser_execute_type_t (*find_something_to_execute)(
cmdparser_context_t *context,
const func_t **ret_builtin,
FvwmFunction **ret_complex_function);
/* Release the context initialised with create_context(). */
void (*destroy_context)(cmdparser_context_t *context);
/* Print the contents of the context. */
void (*debug)(cmdparser_context_t *context, const char *msg);
} cmdparser_hooks_t;

#endif /* CMDPARSER_HOOKS_H */
111 changes: 95 additions & 16 deletions fvwm/cmdparser_old.c
Expand Up @@ -20,25 +20,24 @@
#include "libs/defaults.h"
#include "libs/Parse.h"

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

#include "fvwm.h"
#include "execcontext.h"
#include "conditional.h"
#include "functable.h"
#include "commands.h"
#include "functable_complex.h"
#include "cmdparser.h"
#include "cmdparser_hooks.h"
#include "cmdparser_old.h"
#include "fvwm.h"
#include "misc.h"
#include "execcontext.h"
#include "expand.h"

#define func_t int
#include "functable.h"
#undef func_t

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

#if 1 /*!!!*/
#if 0 /*!!!*/
#define OCP_DEBUG 1
#else
#define OCP_DEBUG 0
Expand Down Expand Up @@ -69,7 +68,7 @@ static void ocp_debug(cmdparser_context_t *c, const char *msg)
return;
}
fprintf(stderr, "%s: %p: %s\n", __func__, c, (msg != NULL) ? msg : "");
if (c->is_created == 0)
if (!c->is_created)
{
fprintf(stderr, " not created\n");
return;
Expand All @@ -82,7 +81,10 @@ static void ocp_debug(cmdparser_context_t *c, const char *msg)
c->do_free_expline, c->expline ? c->expline : "(nil)");
fprintf(
stderr, " command : '%s'\n",
c->command ? c->command: "(nil)");
c->command ? c->command : "(nil)");
fprintf(
stderr, " complexf : '%s'\n",
c->complex_function_name ? c->complex_function_name : "(nil)");
if (c->pos_args == NULL)
{
return;
Expand Down Expand Up @@ -148,15 +150,15 @@ static int ocp_create_context(
static void ocp_destroy_context(cmdparser_context_t *c)
{
/* free the resources allocated in the create function */
if (c->is_created == 0)
if (!c->is_created)
{
return;
}
if (c->command != NULL)
{
free(c->command);
}
if (c->expline != NULL && c->do_free_expline == 1)
if (c->expline != NULL && c->do_free_expline)
{
free(c->expline);
}
Expand Down Expand Up @@ -279,7 +281,7 @@ static const char *ocp_parse_command_name(
c->command, c, False, False, func_rc, exc);
free(tmp);
}
if (c->command && ocp_is_module_config(c) == 0)
if (c->command && !ocp_is_module_config(c))
{
#if 1
/* DV: with this piece of code it is impossible to have a
Expand All @@ -303,14 +305,15 @@ static const char *ocp_parse_command_name(
}
}

static char *ocp_expand_command_line(
static void ocp_expand_command_line(
cmdparser_context_t *c, int is_addto, void *func_rc, const void *exc)
{
c->expline = expand_vars(
c->cline, c, is_addto, ocp_is_module_config(c), func_rc, exc);
c->cline = c->expline;
c->do_free_expline = 1;

return c->expline;
return;
}

static void ocp_release_expanded_line(cmdparser_context_t *c)
Expand All @@ -320,6 +323,81 @@ static void ocp_release_expanded_line(cmdparser_context_t *c)
return;
}

static cmdparser_execute_type_t ocp_find_something_to_execute(
cmdparser_context_t *c, const func_t **ret_builtin,
FvwmFunction **ret_complex_function)
{
int is_function_builtin;

*ret_complex_function = NULL;
/* Note: the module config command, "*" can not be handled by the
* regular command table because there is no required white space after
* the asterisk. */
if (ocp_is_module_config(c))
{
/*!!!strip asterisk??? */
return CP_EXECTYPE_MODULECONFIG;
}
if (*ret_builtin == NULL)
{
/* in a new parser we would look for a builtin function here,
* but in the old parser this has already been done */
}
is_function_builtin = 0;
if (*ret_builtin != NULL)
{
if ((*ret_builtin)->func_c == F_FUNCTION)
{
c->cline = SkipNTokens(c->cline, 1);
if (OCP_DEBUG)
{
fprintf(stderr, "func cline '%s'\n", c->cline);
}
free(c->command);
c->command = NULL;
is_function_builtin = 1;
*ret_builtin = NULL;
}
else
{
c->cline = SkipNTokens(c->cline, 1);
return CP_EXECTYPE_BUILTIN_FUNCTION;
}
}
#if 1 /*!!!*/
assert(*ret_builtin == NULL);
#endif
do
{
char *complex_function_name;
char *rest_of_line;

/* find_complex_function expects a token, not just a quoted
* string */
complex_function_name = PeekToken(c->cline, &rest_of_line);
if (complex_function_name == NULL)
{
break;
}
*ret_complex_function =
find_complex_function(complex_function_name);
if (*ret_complex_function != NULL)
{
c->cline = rest_of_line;
c->complex_function_name = complex_function_name;
return CP_EXECTYPE_COMPLEX_FUNCTION;
}
if (is_function_builtin)
{
c->cline = rest_of_line;
c->complex_function_name = complex_function_name;
return CP_EXECTYPE_COMPLEX_FUNCTION_DOES_NOT_EXIST;
}
} while (0);

return CP_EXECTYPE_UNKNOWN;
}

/* ---------------------------- local variables ---------------------------- */

static cmdparser_hooks_t old_parser_hooks =
Expand All @@ -331,6 +409,7 @@ static cmdparser_hooks_t old_parser_hooks =
ocp_is_module_config,
ocp_expand_command_line,
ocp_release_expanded_line,
ocp_find_something_to_execute,
ocp_destroy_context,
ocp_debug
};
Expand Down

0 comments on commit 7f35780

Please sign in to comment.