]> git.sur5r.net Git - i3/i3/blobdiff - src/cmdparse.y
Bugfix: don’t kill parent when currently in tree_close() for a child of this parent
[i3/i3] / src / cmdparse.y
index f4ad6e078a105b810f85152be8516832ac90bb83..7f9dfd46c2d411d6ccdb0c269e1066507d0d851b 100644 (file)
@@ -37,6 +37,10 @@ typedef struct owindow {
 } 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. */
@@ -45,8 +49,7 @@ static TAILQ_HEAD(owindows_head, owindow) owindows;
 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++)
@@ -55,28 +58,35 @@ void cmdyyerror(const char *error_message) {
         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(&current_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;
 }
 
 %}
@@ -103,6 +113,7 @@ void parse_cmd(const char *new) {
 %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"
@@ -156,7 +167,7 @@ commands: /* empty */
             TAILQ_REMOVE(&owindows, current, owindows);
             free(current);
         }
-        memset(&current_match, 0, sizeof(Match));
+        match_init(&current_match);
     }
     ;
 
@@ -179,7 +190,7 @@ matchstart:
     '['
     {
         printf("start\n");
-        memset(&current_match, '\0', sizeof(Match));
+        match_init(&current_match);
         TAILQ_INIT(&owindows);
         /* copy all_cons */
         Con *con;
@@ -278,8 +289,7 @@ operation:
     | exit
     | restart
     | reload
-    /*
-    | border */
+    | border
     | layout
     | restore
     | move
@@ -372,7 +382,7 @@ kill:
         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);
             }
         }
 
@@ -392,7 +402,8 @@ open:
     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);
     }
     ;
 
@@ -472,6 +483,31 @@ window_mode:
     | 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(&current_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
     {