} 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. */
return 1;
}
-void parse_cmd(const char *new) {
+char *parse_cmd(const char *new) {
//const char *new = "[level-up workspace] attach $output, focus";
context = scalloc(sizeof(struct context));
context->filename = "cmd";
+ FREE(json_output);
if (cmdyyparse() != 0) {
fprintf(stderr, "Could not parse configfile\n");
exit(1);
}
- printf("done\n");
+ printf("done, json output = %s\n", json_output);
FREE(context->line_copy);
free(context);
+ return json_output;
}
%}
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);
}
;
char *command = scalloc(message_size + 1);
strncpy(command, (const char*)message, message_size);
LOG("IPC: received: *%s*\n", command);
- parse_cmd((const char*)command);
+ const char *reply = parse_cmd((const char*)command);
tree_render();
free(command);
- /* For now, every command gets a positive acknowledge
- * (will change with the new command parser) */
- const char *reply = "{\"success\":true}";
+ /* If no reply was provided, we just use the default success message */
+ if (reply == NULL)
+ reply = "{\"success\":true}";
ipc_send_message(fd, (const unsigned char*)reply,
I3_IPC_REPLY_TYPE_COMMAND, strlen(reply));
}