} owindow;
static TAILQ_HEAD(owindows_head, owindow) owindows;
+/* Holds the JSON which will be returned via IPC or NULL for the default return
+ * message */
+static char *json_output;
+
/* We don’t need yydebug for now, as we got decent error messages using
* yyerror(). Should you ever want to extend the parser, it might be handy
* to just comment it in again, so it stays here. */
void cmdyyerror(const char *error_message) {
ELOG("\n");
ELOG("CMD: %s\n", error_message);
- ELOG("CMD: in file \"%s\", line %d:\n",
- context->filename, context->line_number);
+ ELOG("CMD: in command:\n");
ELOG("CMD: %s\n", context->line_copy);
ELOG("CMD: ");
for (int c = 1; c <= context->last_column; c++)
else printf(" ");
printf("\n");
ELOG("\n");
+ context->compact_error = sstrdup(error_message);
}
int cmdyywrap() {
return 1;
}
-void parse_cmd(const char *new) {
-
- //const char *new = "[level-up workspace] attach $output, focus";
-
+char *parse_cmd(const char *new) {
cmdyy_scan_string(new);
+ match_init(¤t_match);
context = scalloc(sizeof(struct context));
context->filename = "cmd";
+ FREE(json_output);
if (cmdyyparse() != 0) {
- fprintf(stderr, "Could not parse configfile\n");
- exit(1);
+ fprintf(stderr, "Could not parse command\n");
+ asprintf(&json_output, "{\"success\":false, \"error\":\"%s at position %d\"}",
+ context->compact_error, context->first_column);
+ FREE(context->line_copy);
+ FREE(context->compact_error);
+ free(context);
+ return json_output;
}
- printf("done\n");
+ printf("done, json output = %s\n", json_output);
FREE(context->line_copy);
+ FREE(context->compact_error);
free(context);
+ return json_output;
}
%}
%token TOK_STACKED "stacked"
%token TOK_TABBED "tabbed"
%token TOK_BORDER "border"
+%token TOK_NORMAL "normal"
%token TOK_NONE "none"
%token TOK_1PIXEL "1pixel"
%token TOK_MODE "mode"
TAILQ_REMOVE(&owindows, current, owindows);
free(current);
}
- memset(¤t_match, 0, sizeof(Match));
+ match_init(¤t_match);
}
;
'['
{
printf("start\n");
- memset(¤t_match, '\0', sizeof(Match));
+ match_init(¤t_match);
TAILQ_INIT(&owindows);
/* copy all_cons */
Con *con;
| exit
| restart
| reload
- /*
- | border */
+ | border
| layout
| restore
| move
else {
TAILQ_FOREACH(current, &owindows, owindows) {
printf("matching: %p / %s\n", current->con, current->con->name);
- tree_close(current->con, true);
+ tree_close(current->con, true, false);
}
}
TOK_OPEN
{
printf("opening new container\n");
- tree_open_con(NULL);
+ Con *con = tree_open_con(NULL);
+ asprintf(&json_output, "{\"success\":true, \"id\":%d}", (long int)con);
}
;
| TOK_TOGGLE { $<number>$ = TOK_TOGGLE; }
;
+border:
+ TOK_BORDER WHITESPACE border_style
+ {
+ printf("border style should be changed to %d\n", $<number>3);
+ owindow *current;
+
+ /* check if the match is empty, not if the result is empty */
+ if (match_is_empty(¤t_match))
+ focused->border_style = $<number>3;
+ else {
+ TAILQ_FOREACH(current, &owindows, owindows) {
+ printf("matching: %p / %s\n", current->con, current->con->name);
+ current->con->border_style = $<number>3;
+ }
+ }
+ }
+ ;
+
+border_style:
+ TOK_NORMAL { $<number>$ = BS_NORMAL; }
+ | TOK_NONE { $<number>$ = BS_NONE; }
+ | TOK_1PIXEL { $<number>$ = BS_1PIXEL; }
+ ;
+
+
level:
TOK_LEVEL WHITESPACE level_direction
{