static void line_callback(pa_ioline *line, const char *s, void *userdata) { pa_strbuf *buf; pa_cli *c = userdata; char *p; pa_assert(line); pa_assert(c); if (!s) { pa_log_debug("CLI got EOF from user."); if (c->eof_callback) c->eof_callback(c, c->userdata); return; } /* Magic command, like they had in AT Hayes Modems! Those were the good days! */ if (pa_streq(s, "/")) s = c->last_line; else if (s[0]) { pa_xfree(c->last_line); c->last_line = pa_xstrdup(s); } pa_assert_se(buf = pa_strbuf_new()); c->defer_kill++; if (pa_streq(s, "hello")) { pa_strbuf_printf(buf, "Welcome to PulseAudio %s! " "Use \"help\" for usage information.\n", PACKAGE_VERSION); c->interactive = true; } else pa_cli_command_execute_line(c->core, s, buf, &c->fail); c->defer_kill--; pa_ioline_puts(line, p = pa_strbuf_to_string_free(buf)); pa_xfree(p); if (c->kill_requested) { if (c->eof_callback) c->eof_callback(c, c->userdata); } else if (c->interactive) pa_ioline_puts(line, PROMPT); }
static void line_callback(pa_ioline *line, const char *s, void *userdata) { pa_strbuf *buf; pa_cli *c = userdata; char *p; pa_assert(line); pa_assert(c); if (!s) { pa_log_debug("CLI got EOF from user."); if (c->eof_callback) c->eof_callback(c, c->userdata); return; } /* Magic command, like they had in AT Hayes Modems! Those were the good days! */ if (pa_streq(s, "/")) s = c->last_line; else if (s[0]) { pa_xfree(c->last_line); c->last_line = pa_xstrdup(s); } pa_assert_se(buf = pa_strbuf_new()); c->defer_kill++; pa_cli_command_execute_line(c->core, s, buf, &c->fail); c->defer_kill--; pa_ioline_puts(line, p = pa_strbuf_tostring_free(buf)); pa_xfree(p); if (c->kill_requested) { if (c->eof_callback) c->eof_callback(c, c->userdata); } else pa_ioline_puts(line, PROMPT); }