i3
Data Structures | Macros | Typedefs | Functions | Variables
commands_parser.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdint.h>
#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
 
struct  stack_entry
 

Macros

#define I3__FILE__   "commands_parser.c"
 
#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 (const char *identifier, char *str)
 
static char * get_string (const char *identifier)
 
static void clear_stack (void)
 
static void next_state (const cmdp_token *token)
 
CommandResultparse_command (const char *input, yajl_gen gen)
 Parses and executes the given command. More...
 
void command_result_free (CommandResult *result)
 Frees a CommandResult. More...
 

Variables

static struct stack_entry stack [10]
 
static cmdp_state state
 
static Match current_match
 
static struct CommandResultIR subcommand_output
 
static struct CommandResultIR command_output
 

Macro Definition Documentation

#define I3__FILE__   "commands_parser.c"

Definition at line 2 of file commands_parser.c.

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

Definition at line 38 of file commands_parser.c.

Referenced by parse_command().

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

Definition at line 39 of file commands_parser.c.

Referenced by parse_command().

Typedef Documentation

typedef struct token cmdp_token
typedef struct tokenptr cmdp_token_ptr

Function Documentation

static void clear_stack ( void  )
static

Definition at line 118 of file commands_parser.c.

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

Referenced by next_state(), and parse_command().

void command_result_free ( CommandResult result)

Frees a CommandResult.

Definition at line 424 of file commands_parser.c.

References CommandResult::error_message, and FREE.

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

static char* get_string ( const char *  identifier)
static

Definition at line 108 of file commands_parser.c.

References stack, and stack_entry::str.

Referenced by GENERATED_call().

static void next_state ( const cmdp_token token)
static
CommandResult* parse_command ( const char *  input,
yajl_gen  gen 
)

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 214 of file commands_parser.c.

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

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

Here is the call graph for this function:

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

Definition at line 87 of file commands_parser.c.

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

Referenced by parse_command().

Variable Documentation

struct CommandResultIR command_output
static

Definition at line 183 of file commands_parser.c.

Referenced by next_state(), and parse_command().

Match current_match
static
struct stack_entry stack[10]
static

Definition at line 80 of file commands_parser.c.

Referenced by clear_stack(), get_string(), and push_string().

cmdp_state state
static
struct CommandResultIR subcommand_output
static

Definition at line 182 of file commands_parser.c.

Referenced by next_state(), and parse_command().