4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
32 #include "cli-command.h"
37 #include "sink-input.h"
38 #include "source-output.h"
39 #include "tokenizer.h"
44 #include "sample-util.h"
45 #include "sound-file.h"
46 #include "play-memchunk.h"
49 #include "sound-file-stream.h"
53 int (*proc) (struct pa_core *c, struct pa_tokenizer*t, struct pa_strbuf *buf, int *fail, int *verbose);
58 static int pa_cli_command_exit(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
59 static int pa_cli_command_help(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
60 static int pa_cli_command_modules(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
61 static int pa_cli_command_clients(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
62 static int pa_cli_command_sinks(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
63 static int pa_cli_command_sources(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
64 static int pa_cli_command_sink_inputs(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
65 static int pa_cli_command_source_outputs(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
66 static int pa_cli_command_stat(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
67 static int pa_cli_command_info(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
68 static int pa_cli_command_load(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
69 static int pa_cli_command_unload(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
70 static int pa_cli_command_sink_volume(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
71 static int pa_cli_command_sink_input_volume(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
72 static int pa_cli_command_sink_default(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
73 static int pa_cli_command_source_default(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
74 static int pa_cli_command_kill_client(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
75 static int pa_cli_command_kill_sink_input(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
76 static int pa_cli_command_kill_source_output(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
77 static int pa_cli_command_scache_play(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
78 static int pa_cli_command_scache_remove(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
79 static int pa_cli_command_scache_list(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
80 static int pa_cli_command_scache_load(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
81 static int pa_cli_command_play_file(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
82 static int pa_cli_command_autoload_list(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
83 static int pa_cli_command_autoload_add(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
84 static int pa_cli_command_autoload_remove(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
86 static const struct command commands[] = {
87 { "exit", pa_cli_command_exit, "Terminate the daemon", 1 },
88 { "help", pa_cli_command_help, "Show this help", 1 },
89 { "modules", pa_cli_command_modules, "List loaded modules", 1 },
90 { "sinks", pa_cli_command_sinks, "List loaded sinks", 1 },
91 { "sources", pa_cli_command_sources, "List loaded sources", 1 },
92 { "clients", pa_cli_command_clients, "List loaded clients", 1 },
93 { "sink_inputs", pa_cli_command_sink_inputs, "List sink inputs", 1 },
94 { "source_outputs", pa_cli_command_source_outputs, "List source outputs", 1 },
95 { "stat", pa_cli_command_stat, "Show memory block statistics", 1 },
96 { "info", pa_cli_command_info, "Show comprehensive status", 1 },
97 { "ls", pa_cli_command_info, NULL, 1 },
98 { "list", pa_cli_command_info, NULL, 1 },
99 { "load", pa_cli_command_load, "Load a module (args: name, arguments)", 3},
100 { "unload", pa_cli_command_unload, "Unload a module (args: index)", 2},
101 { "sink_volume", pa_cli_command_sink_volume, "Set the volume of a sink (args: index|name, volume)", 3},
102 { "sink_input_volume", pa_cli_command_sink_input_volume, "Set the volume of a sink input (args: index|name, volume)", 3},
103 { "sink_default", pa_cli_command_sink_default, "Set the default sink (args: index|name)", 2},
104 { "source_default", pa_cli_command_source_default, "Set the default source (args: index|name)", 2},
105 { "kill_client", pa_cli_command_kill_client, "Kill a client (args: index)", 2},
106 { "kill_sink_input", pa_cli_command_kill_sink_input, "Kill a sink input (args: index)", 2},
107 { "kill_source_output", pa_cli_command_kill_source_output, "Kill a source output (args: index)", 2},
108 { "scache_list", pa_cli_command_scache_list, "List all entries in the sample cache", 1},
109 { "scache_play", pa_cli_command_scache_play, "Play a sample from the sample cache (args: name, sink|index)", 3},
110 { "scache_remove", pa_cli_command_scache_remove, "Remove a sample from the sample cache (args: name)", 2},
111 { "scache_load", pa_cli_command_scache_load, "Load a sound file into the sample cache (args: filename,name)", 3},
112 { "play_file", pa_cli_command_play_file, "Play a sound file (args: filename, sink|index)", 3},
113 { "autoload_list", pa_cli_command_autoload_list, "List autoload entries", 1},
114 { "autoload_sink_add", pa_cli_command_autoload_add, "Add autoload entry for a sink (args: sink, name, arguments)", 4},
115 { "autoload_source_add", pa_cli_command_autoload_add, "Add autoload entry for a source (args: source, name, arguments)", 4},
116 { "autoload_sink_remove", pa_cli_command_autoload_remove, "Remove autoload entry for a sink (args: sink)", 2},
117 { "autoload_source_remove", pa_cli_command_autoload_remove, "Remove autoload entry for a source (args: source)", 2},
118 { NULL, NULL, NULL, 0 }
121 static const char whitespace[] = " \t\n\r";
122 static const char linebreak[] = "\n\r";
124 static uint32_t parse_index(const char *n) {
127 index = strtol(n, &x, 0);
128 if (!x || *x != 0 || index < 0)
129 return (uint32_t) PA_IDXSET_INVALID;
131 return (uint32_t) index;
134 static int pa_cli_command_exit(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
135 assert(c && c->mainloop && t);
136 c->mainloop->quit(c->mainloop, 0);
140 static int pa_cli_command_help(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
141 const struct command*command;
142 assert(c && t && buf);
144 pa_strbuf_puts(buf, "Available commands:\n");
146 for (command = commands; command->name; command++)
148 pa_strbuf_printf(buf, " %-20s %s\n", command->name, command->help);
152 static int pa_cli_command_modules(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
155 s = pa_module_list_to_string(c);
157 pa_strbuf_puts(buf, s);
162 static int pa_cli_command_clients(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
165 s = pa_client_list_to_string(c);
167 pa_strbuf_puts(buf, s);
172 static int pa_cli_command_sinks(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
175 s = pa_sink_list_to_string(c);
177 pa_strbuf_puts(buf, s);
182 static int pa_cli_command_sources(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
185 s = pa_source_list_to_string(c);
187 pa_strbuf_puts(buf, s);
192 static int pa_cli_command_sink_inputs(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
195 s = pa_sink_input_list_to_string(c);
197 pa_strbuf_puts(buf, s);
202 static int pa_cli_command_source_outputs(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
205 s = pa_source_output_list_to_string(c);
207 pa_strbuf_puts(buf, s);
212 static int pa_cli_command_stat(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
216 pa_bytes_snprint(s, sizeof(s), c->memblock_stat->total_size);
217 pa_strbuf_printf(buf, "Memory blocks currently allocated: %u, size: %s.\n",
218 c->memblock_stat->total,
221 pa_bytes_snprint(s, sizeof(s), c->memblock_stat->allocated_size);
222 pa_strbuf_printf(buf, "Memory blocks allocated during the whole lifetime: %u, size: %s.\n",
223 c->memblock_stat->allocated,
226 pa_bytes_snprint(s, sizeof(s), pa_scache_total_size(c));
227 pa_strbuf_printf(buf, "Total sample cache size: %s.\n", s);
229 pa_sample_spec_snprint(s, sizeof(s), &c->default_sample_spec);
230 pa_strbuf_printf(buf, "Default sample spec: %s\n", s);
232 pa_strbuf_printf(buf, "Default sink name: %s\n"
233 "Default source name: %s\n",
234 pa_namereg_get_default_sink_name(c),
235 pa_namereg_get_default_source_name(c));
240 static int pa_cli_command_info(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
242 pa_cli_command_stat(c, t, buf, fail, verbose);
243 pa_cli_command_modules(c, t, buf, fail, verbose);
244 pa_cli_command_sinks(c, t, buf, fail, verbose);
245 pa_cli_command_sources(c, t, buf, fail, verbose);
246 pa_cli_command_clients(c, t, buf, fail, verbose);
247 pa_cli_command_sink_inputs(c, t, buf, fail, verbose);
248 pa_cli_command_source_outputs(c, t, buf, fail, verbose);
249 pa_cli_command_scache_list(c, t, buf, fail, verbose);
250 pa_cli_command_autoload_list(c, t, buf, fail, verbose);
254 static int pa_cli_command_load(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
260 if (!(name = pa_tokenizer_get(t, 1))) {
261 pa_strbuf_puts(buf, "You need to specify the module name and optionally arguments.\n");
265 if (!(m = pa_module_load(c, name, pa_tokenizer_get(t, 2)))) {
266 pa_strbuf_puts(buf, "Module load failed.\n");
271 snprintf(txt, sizeof(txt), "Module successfully loaded, index: %u.\n", m->index);
272 pa_strbuf_puts(buf, txt);
277 static int pa_cli_command_unload(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
284 if (!(i = pa_tokenizer_get(t, 1))) {
285 pa_strbuf_puts(buf, "You need to specify the module index.\n");
289 index = (uint32_t) strtoul(i, &e, 10);
290 if (*e || !(m = pa_idxset_get_by_index(c->modules, index))) {
291 pa_strbuf_puts(buf, "Invalid module index.\n");
295 pa_module_unload_request(c, m);
299 static int pa_cli_command_sink_volume(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
302 struct pa_sink *sink;
305 if (!(n = pa_tokenizer_get(t, 1))) {
306 pa_strbuf_puts(buf, "You need to specify a sink either by its name or its index.\n");
310 if (!(v = pa_tokenizer_get(t, 2))) {
311 pa_strbuf_puts(buf, "You need to specify a volume >= 0. (0 is muted, 0x100 is normal volume)\n");
315 volume = strtol(v, &x, 0);
316 if (!x || *x != 0 || volume < 0) {
317 pa_strbuf_puts(buf, "Failed to parse volume.\n");
321 if (!(sink = pa_namereg_get(c, n, PA_NAMEREG_SINK, 1))) {
322 pa_strbuf_puts(buf, "No sink found by this name or index.\n");
326 pa_sink_set_volume(sink, (uint32_t) volume);
330 static int pa_cli_command_sink_input_volume(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
332 struct pa_sink_input *si;
337 if (!(n = pa_tokenizer_get(t, 1))) {
338 pa_strbuf_puts(buf, "You need to specify a sink input by its index.\n");
342 if ((index = parse_index(n)) == PA_IDXSET_INVALID) {
343 pa_strbuf_puts(buf, "Failed to parse index.\n");
347 if (!(v = pa_tokenizer_get(t, 2))) {
348 pa_strbuf_puts(buf, "You need to specify a volume >= 0. (0 is muted, 0x100 is normal volume)\n");
353 volume = strtol(v, &x, 0);
354 if (!x || *x != 0 || volume < 0) {
355 pa_strbuf_puts(buf, "Failed to parse volume.\n");
359 if (!(si = pa_idxset_get_by_index(c->sink_inputs, (uint32_t) index))) {
360 pa_strbuf_puts(buf, "No sink input found with this index.\n");
364 pa_sink_input_set_volume(si, (uint32_t) volume);
368 static int pa_cli_command_sink_default(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
372 if (!(n = pa_tokenizer_get(t, 1))) {
373 pa_strbuf_puts(buf, "You need to specify a sink either by its name or its index.\n");
377 pa_namereg_set_default(c, n, PA_NAMEREG_SINK);
381 static int pa_cli_command_source_default(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
385 if (!(n = pa_tokenizer_get(t, 1))) {
386 pa_strbuf_puts(buf, "You need to specify a source either by its name or its index.\n");
390 pa_namereg_set_default(c, n, PA_NAMEREG_SOURCE);
394 static int pa_cli_command_kill_client(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
396 struct pa_client *client;
400 if (!(n = pa_tokenizer_get(t, 1))) {
401 pa_strbuf_puts(buf, "You need to specify a client by its index.\n");
405 if ((index = parse_index(n)) == PA_IDXSET_INVALID) {
406 pa_strbuf_puts(buf, "Failed to parse index.\n");
410 if (!(client = pa_idxset_get_by_index(c->clients, index))) {
411 pa_strbuf_puts(buf, "No client found by this index.\n");
415 pa_client_kill(client);
419 static int pa_cli_command_kill_sink_input(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
421 struct pa_sink_input *sink_input;
425 if (!(n = pa_tokenizer_get(t, 1))) {
426 pa_strbuf_puts(buf, "You need to specify a sink input by its index.\n");
430 if ((index = parse_index(n)) == PA_IDXSET_INVALID) {
431 pa_strbuf_puts(buf, "Failed to parse index.\n");
435 if (!(sink_input = pa_idxset_get_by_index(c->sink_inputs, index))) {
436 pa_strbuf_puts(buf, "No sink input found by this index.\n");
440 pa_sink_input_kill(sink_input);
444 static int pa_cli_command_kill_source_output(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
446 struct pa_source_output *source_output;
450 if (!(n = pa_tokenizer_get(t, 1))) {
451 pa_strbuf_puts(buf, "You need to specify a source output by its index.\n");
455 if ((index = parse_index(n)) == PA_IDXSET_INVALID) {
456 pa_strbuf_puts(buf, "Failed to parse index.\n");
460 if (!(source_output = pa_idxset_get_by_index(c->source_outputs, index))) {
461 pa_strbuf_puts(buf, "No source output found by this index.\n");
465 pa_source_output_kill(source_output);
469 static int pa_cli_command_scache_list(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
472 s = pa_scache_list_to_string(c);
474 pa_strbuf_puts(buf, s);
479 static int pa_cli_command_scache_play(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
480 const char *n, *sink_name;
481 struct pa_sink *sink;
482 assert(c && t && buf && fail && verbose);
484 if (!(n = pa_tokenizer_get(t, 1)) || !(sink_name = pa_tokenizer_get(t, 2))) {
485 pa_strbuf_puts(buf, "You need to specify a sample name and a sink name.\n");
489 if (!(sink = pa_namereg_get(c, sink_name, PA_NAMEREG_SINK, 1))) {
490 pa_strbuf_puts(buf, "No sink by that name.\n");
494 if (pa_scache_play_item(c, n, sink, PA_VOLUME_NORM) < 0) {
495 pa_strbuf_puts(buf, "Failed to play sample.\n");
502 static int pa_cli_command_scache_remove(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
504 assert(c && t && buf && fail && verbose);
506 if (!(n = pa_tokenizer_get(t, 1))) {
507 pa_strbuf_puts(buf, "You need to specify a sample name.\n");
511 if (pa_scache_remove_item(c, n) < 0) {
512 pa_strbuf_puts(buf, "Failed to remove sample.\n");
519 static int pa_cli_command_scache_load(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
520 const char *fname, *n;
521 struct pa_memchunk chunk;
522 struct pa_sample_spec ss;
523 assert(c && t && buf && fail && verbose);
525 if (!(fname = pa_tokenizer_get(t, 1)) || !(n = pa_tokenizer_get(t, 2))) {
526 pa_strbuf_puts(buf, "You need to specify a file name and a sample name.\n");
530 if (pa_sound_file_load(fname, &ss, &chunk, c->memblock_stat) < 0) {
531 pa_strbuf_puts(buf, "Failed to load sound file.\n");
535 pa_scache_add_item(c, n, &ss, &chunk, NULL);
536 pa_memblock_unref(chunk.memblock);
540 static int pa_cli_command_play_file(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
541 const char *fname, *sink_name;
542 struct pa_sink *sink;
543 assert(c && t && buf && fail && verbose);
545 if (!(fname = pa_tokenizer_get(t, 1)) || !(sink_name = pa_tokenizer_get(t, 2))) {
546 pa_strbuf_puts(buf, "You need to specify a file name and a sink name.\n");
550 if (!(sink = pa_namereg_get(c, sink_name, PA_NAMEREG_SINK, 1))) {
551 pa_strbuf_puts(buf, "No sink by that name.\n");
556 return pa_play_file(sink, fname, PA_VOLUME_NORM);
559 static int pa_cli_command_autoload_add(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
560 const char *devname, *module;
561 assert(c && t && buf && fail && verbose);
563 if (!(devname = pa_tokenizer_get(t, 1)) || !(module = pa_tokenizer_get(t, 2))) {
564 pa_strbuf_puts(buf, "You need to specify a device name, a module name and optionally module arguments\n");
568 pa_autoload_add(c, devname, strstr(pa_tokenizer_get(t, 0), "sink") ? PA_NAMEREG_SINK : PA_NAMEREG_SOURCE, module, pa_tokenizer_get(t, 3));
572 static int pa_cli_command_autoload_remove(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
574 assert(c && t && buf && fail && verbose);
576 if (!(devname = pa_tokenizer_get(t, 1))) {
577 pa_strbuf_puts(buf, "You need to specify a device name\n");
581 if (pa_autoload_remove(c, devname, strstr(pa_tokenizer_get(t, 0), "sink") ? PA_NAMEREG_SINK : PA_NAMEREG_SOURCE) < 0) {
582 pa_strbuf_puts(buf, "Failed to remove autload entry\n");
589 static int pa_cli_command_autoload_list(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
592 s = pa_autoload_list_to_string(c);
594 pa_strbuf_puts(buf, s);
599 int pa_cli_command_execute_line(struct pa_core *c, const char *s, struct pa_strbuf *buf, int *fail, int *verbose) {
602 cs = s+strspn(s, whitespace);
604 if (*cs == '#' || !*cs)
606 else if (*cs == '.') {
607 static const char fail_meta[] = ".fail";
608 static const char nofail_meta[] = ".nofail";
609 static const char verbose_meta[] = ".verbose";
610 static const char noverbose_meta[] = ".noverbose";
612 if (!strcmp(cs, verbose_meta))
614 else if (!strcmp(cs, noverbose_meta))
616 else if (!strcmp(cs, fail_meta))
618 else if (!strcmp(cs, nofail_meta))
622 static const char include_meta[] = ".include";
623 l = strcspn(cs, whitespace);
625 if (l == sizeof(include_meta)-1 && !strncmp(cs, include_meta, l)) {
626 const char *filename = cs+l+strspn(cs+l, whitespace);
628 if (pa_cli_command_execute_file(c, filename, buf, fail, verbose) < 0)
629 if (*fail) return -1;
631 pa_strbuf_printf(buf, "Invalid meta command: %s\n", cs);
632 if (*fail) return -1;
636 const struct command*command;
640 l = strcspn(cs, whitespace);
642 for (command = commands; command->name; command++)
643 if (strlen(command->name) == l && !strncmp(cs, command->name, l)) {
645 struct pa_tokenizer *t = pa_tokenizer_new(cs, command->args);
647 ret = command->proc(c, t, buf, fail, verbose);
648 pa_tokenizer_free(t);
651 if (ret < 0 && *fail)
658 pa_strbuf_printf(buf, "Unknown command: %s\n", cs);
667 int pa_cli_command_execute_file(struct pa_core *c, const char *fn, struct pa_strbuf *buf, int *fail, int *verbose) {
671 assert(c && fn && buf);
673 if (!(f = fopen(fn, "r"))) {
674 pa_strbuf_printf(buf, "open('%s') failed: %s\n", fn, strerror(errno));
681 pa_strbuf_printf(buf, "Executing file: '%s'\n", fn);
683 while (fgets(line, sizeof(line), f)) {
684 char *e = line + strcspn(line, linebreak);
687 if (pa_cli_command_execute_line(c, line, buf, fail, verbose) < 0 && *fail)
692 pa_strbuf_printf(buf, "Executed file: '%s'\n", fn);
703 int pa_cli_command_execute(struct pa_core *c, const char *s, struct pa_strbuf *buf, int *fail, int *verbose) {
705 assert(c && s && buf && fail && verbose);
709 size_t l = strcspn(p, linebreak);
710 char *line = pa_xstrndup(p, l);
712 if (pa_cli_command_execute_line(c, line, buf, fail, verbose) < 0&& *fail) {
719 p += strspn(p, linebreak);