i3
Data Structures | Macros | Typedefs | Functions | Variables
commands_parser.c File Reference
#include "all.h"
#include "GENERATED_command_enums.h"
#include "GENERATED_command_tokens.h"
#include "GENERATED_command_call.h"
Include dependency graph for commands_parser.c:

Go to the source code of this file.

Data Structures

struct  token
 
struct  tokenptr
 

Macros

#define y(x, ...)   (command_output.json_gen != NULL ? yajl_gen_##x(command_output.json_gen, ##__VA_ARGS__) : 0)
 
#define ystr(str)   (command_output.json_gen != NULL ? yajl_gen_string(command_output.json_gen, (unsigned char *)str, strlen(str)) : 0)
 

Typedefs

typedef struct token cmdp_token
 
typedef struct tokenptr cmdp_token_ptr
 

Functions

static void push_string (struct stack *stack, const char *identifier, char *str)
 
static void push_long (struct stack *stack, const char *identifier, long num)
 
static const char * get_string (struct stack *stack, const char *identifier)
 
static long get_long (struct stack *stack, const char *identifier)
 
static void clear_stack (struct stack *stack)
 
static void next_state (const cmdp_token *token)
 
char * parse_string (const char **walk, bool as_word)
 Parses a string (or word, if as_word is true).
 
CommandResultparse_command (const char *input, yajl_gen gen, ipc_client *client)
 Parses and executes the given command.
 
void command_result_free (CommandResult *result)
 Frees a CommandResult.
 

Variables

static cmdp_state state
 
static Match current_match
 
static struct stack stack
 
static struct CommandResultIR subcommand_output
 
static struct CommandResultIR command_output
 

Macro Definition Documentation

◆ y

#define y (   x,
  ... 
)    (command_output.json_gen != NULL ? yajl_gen_##x(command_output.json_gen, ##__VA_ARGS__) : 0)

Definition at line 29 of file commands_parser.c.

◆ ystr

#define ystr (   str)    (command_output.json_gen != NULL ? yajl_gen_string(command_output.json_gen, (unsigned char *)str, strlen(str)) : 0)

Definition at line 30 of file commands_parser.c.

Typedef Documentation

◆ cmdp_token

typedef struct token cmdp_token

◆ cmdp_token_ptr

typedef struct tokenptr cmdp_token_ptr

Function Documentation

◆ clear_stack()

static void clear_stack ( struct stack stack)
static

Definition at line 130 of file commands_parser.c.

References stack_entry::identifier, stack_entry::num, stack::stack, stack_entry::str, stack_entry::type, and stack_entry::val.

Referenced by next_state(), and parse_command().

Here is the call graph for this function:

◆ command_result_free()

void command_result_free ( CommandResult result)

◆ get_long()

static long get_long ( struct stack stack,
const char *  identifier 
)
static

Definition at line 118 of file commands_parser.c.

References stack_entry::identifier, stack_entry::num, stack::stack, and stack_entry::val.

Here is the call graph for this function:

◆ get_string()

static const char * get_string ( struct stack stack,
const char *  identifier 
)
static

Definition at line 107 of file commands_parser.c.

References stack_entry::identifier, stack::stack, stack_entry::str, and stack_entry::val.

Here is the call graph for this function:

◆ next_state()

static void next_state ( const cmdp_token token)
static

◆ parse_command()

CommandResult * parse_command ( const char *  input,
yajl_gen  gen,
ipc_client client 
)

Parses and executes the given command.

If a caller-allocated yajl_gen is passed, a json reply will be generated in the format specified by the ipc protocol. Pass NULL if no json reply is required.

Free the returned CommandResult with command_result_free().

Definition at line 240 of file commands_parser.c.

References tokenptr::array, clear_stack(), CommandResultIR::client, cmd_criteria_init(), command_output, current_match, DLOG, ELOG, CommandResult::error_message, token::identifier, CommandResultIR::json_gen, tokenptr::n, token::name, CommandResultIR::needs_tree_render, CommandResult::needs_tree_render, next_state(), CommandResult::parse_error, parse_string(), push_long(), push_string(), sasprintf(), scalloc(), smalloc(), sstrdup(), state, subcommand_output, y, and ystr.

Referenced by IPC_HANDLER(), run_assignments(), and run_binding().

Here is the call graph for this function:

◆ parse_string()

char * parse_string ( const char **  walk,
bool  as_word 
)

Parses a string (or word, if as_word is true).

Extracted out of parse_command so that it can be used in src/workspace.c for interpreting workspace commands.

Definition at line 183 of file commands_parser.c.

References scalloc().

Referenced by extract_workspace_names_from_bindings(), and parse_command().

Here is the call graph for this function:

◆ push_long()

static void push_long ( struct stack stack,
const char *  identifier,
long  num 
)
static

Definition at line 85 of file commands_parser.c.

References stack_entry::identifier, stack_entry::num, stack::stack, stack_entry::type, and stack_entry::val.

Referenced by parse_command().

Here is the call graph for this function:

◆ push_string()

static void push_string ( struct stack stack,
const char *  identifier,
char *  str 
)
static

Definition at line 64 of file commands_parser.c.

References stack_entry::identifier, stack::stack, stack_entry::str, stack_entry::type, and stack_entry::val.

Referenced by parse_command().

Here is the call graph for this function:

Variable Documentation

◆ command_output

struct CommandResultIR command_output
static

Definition at line 152 of file commands_parser.c.

Referenced by next_state(), and parse_command().

◆ current_match

Match current_match
static

◆ stack

struct stack stack
static

Definition at line 150 of file commands_parser.c.

◆ state

cmdp_state state
static

◆ subcommand_output

struct CommandResultIR subcommand_output
static

Definition at line 151 of file commands_parser.c.

Referenced by next_state(), next_state(), parse_command(), and parse_config().