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"
52 int (*proc) (struct pa_core *c, struct pa_tokenizer*t, struct pa_strbuf *buf, int *fail, int *verbose);
57 static int pa_cli_command_exit(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
58 static int pa_cli_command_help(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
59 static int pa_cli_command_modules(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
60 static int pa_cli_command_clients(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
61 static int pa_cli_command_sinks(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
62 static int pa_cli_command_sources(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
63 static int pa_cli_command_sink_inputs(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
64 static int pa_cli_command_source_outputs(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
65 static int pa_cli_command_stat(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
66 static int pa_cli_command_info(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
67 static int pa_cli_command_load(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
68 static int pa_cli_command_unload(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
69 static int pa_cli_command_sink_volume(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
70 static int pa_cli_command_sink_input_volume(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
71 static int pa_cli_command_sink_default(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
72 static int pa_cli_command_source_default(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
73 static int pa_cli_command_kill_client(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
74 static int pa_cli_command_kill_sink_input(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
75 static int pa_cli_command_kill_source_output(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
76 static int pa_cli_command_scache_play(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
77 static int pa_cli_command_scache_remove(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
78 static int pa_cli_command_scache_list(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
79 static int pa_cli_command_scache_load(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
80 static int pa_cli_command_play_file(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
81 static int pa_cli_command_autoload_list(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
82 static int pa_cli_command_autoload_add(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
83 static int pa_cli_command_autoload_remove(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
85 static const struct command commands[] = {
86 { "exit", pa_cli_command_exit, "Terminate the daemon", 1 },
87 { "help", pa_cli_command_help, "Show this help", 1 },
88 { "modules", pa_cli_command_modules, "List loaded modules", 1 },
89 { "sinks", pa_cli_command_sinks, "List loaded sinks", 1 },
90 { "sources", pa_cli_command_sources, "List loaded sources", 1 },
91 { "clients", pa_cli_command_clients, "List loaded clients", 1 },
92 { "sink_inputs", pa_cli_command_sink_inputs, "List sink inputs", 1 },
93 { "source_outputs", pa_cli_command_source_outputs, "List source outputs", 1 },
94 { "stat", pa_cli_command_stat, "Show memory block statistics", 1 },
95 { "info", pa_cli_command_info, "Show comprehensive status", 1 },
96 { "ls", pa_cli_command_info, NULL, 1 },
97 { "list", pa_cli_command_info, NULL, 1 },
98 { "load", pa_cli_command_load, "Load a module (args: name, arguments)", 3},
99 { "unload", pa_cli_command_unload, "Unload a module (args: index)", 2},
100 { "sink_volume", pa_cli_command_sink_volume, "Set the volume of a sink (args: index|name, volume)", 3},
101 { "sink_input_volume", pa_cli_command_sink_input_volume, "Set the volume of a sink input (args: index|name, volume)", 3},
102 { "sink_default", pa_cli_command_sink_default, "Set the default sink (args: index|name)", 2},
103 { "source_default", pa_cli_command_source_default, "Set the default source (args: index|name)", 2},
104 { "kill_client", pa_cli_command_kill_client, "Kill a client (args: index)", 2},
105 { "kill_sink_input", pa_cli_command_kill_sink_input, "Kill a sink input (args: index)", 2},
106 { "kill_source_output", pa_cli_command_kill_source_output, "Kill a source output (args: index)", 2},
107 { "scache_list", pa_cli_command_scache_list, "List all entries in the sample cache", 1},
108 { "scache_play", pa_cli_command_scache_play, "Play a sample from the sample cache (args: name, sink|index)", 3},
109 { "scache_remove", pa_cli_command_scache_remove, "Remove a sample from the sample cache (args: name)", 2},
110 { "scache_load", pa_cli_command_scache_load, "Load a sound file into the sample cache (args: filename,name)", 3},
111 { "play_file", pa_cli_command_play_file, "Play a sound file (args: filename, sink|index)", 3},
112 { "autoload_list", pa_cli_command_autoload_list, "List autoload entries", 1},
113 { "autoload_sink_add", pa_cli_command_autoload_add, "Add autoload entry for a sink (args: sink, name, arguments)", 4},
114 { "autoload_source_add", pa_cli_command_autoload_add, "Add autoload entry for a source (args: source, name, arguments)", 4},
115 { "autoload_sink_remove", pa_cli_command_autoload_remove, "Remove autoload entry for a sink (args: sink)", 2},
116 { "autoload_source_remove", pa_cli_command_autoload_remove, "Remove autoload entry for a source (args: source)", 2},
117 { NULL, NULL, NULL, 0 }
120 static const char whitespace[] = " \t\n\r";
121 static const char linebreak[] = "\n\r";
123 static uint32_t parse_index(const char *n) {
126 index = strtol(n, &x, 0);
127 if (!x || *x != 0 || index < 0)
128 return (uint32_t) PA_IDXSET_INVALID;
130 return (uint32_t) index;
133 static int pa_cli_command_exit(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
134 assert(c && c->mainloop && t);
135 c->mainloop->quit(c->mainloop, 0);
139 static int pa_cli_command_help(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
140 const struct command*command;
141 assert(c && t && buf);
143 pa_strbuf_puts(buf, "Available commands:\n");
145 for (command = commands; command->name; command++)
147 pa_strbuf_printf(buf, " %-20s %s\n", command->name, command->help);
151 static int pa_cli_command_modules(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
154 s = pa_module_list_to_string(c);
156 pa_strbuf_puts(buf, s);
161 static int pa_cli_command_clients(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
164 s = pa_client_list_to_string(c);
166 pa_strbuf_puts(buf, s);
171 static int pa_cli_command_sinks(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
174 s = pa_sink_list_to_string(c);
176 pa_strbuf_puts(buf, s);
181 static int pa_cli_command_sources(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
184 s = pa_source_list_to_string(c);
186 pa_strbuf_puts(buf, s);
191 static int pa_cli_command_sink_inputs(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
194 s = pa_sink_input_list_to_string(c);
196 pa_strbuf_puts(buf, s);
201 static int pa_cli_command_source_outputs(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
204 s = pa_source_output_list_to_string(c);
206 pa_strbuf_puts(buf, s);
211 static int pa_cli_command_stat(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
213 pa_strbuf_printf(buf, "Memory blocks allocated: %u, total size: %u bytes.\n", pa_memblock_get_count(), pa_memblock_get_total());
217 static int pa_cli_command_info(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
219 pa_cli_command_stat(c, t, buf, fail, verbose);
220 pa_cli_command_modules(c, t, buf, fail, verbose);
221 pa_cli_command_sinks(c, t, buf, fail, verbose);
222 pa_cli_command_sources(c, t, buf, fail, verbose);
223 pa_cli_command_clients(c, t, buf, fail, verbose);
224 pa_cli_command_sink_inputs(c, t, buf, fail, verbose);
225 pa_cli_command_source_outputs(c, t, buf, fail, verbose);
226 pa_cli_command_scache_list(c, t, buf, fail, verbose);
227 pa_cli_command_autoload_list(c, t, buf, fail, verbose);
231 static int pa_cli_command_load(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
237 if (!(name = pa_tokenizer_get(t, 1))) {
238 pa_strbuf_puts(buf, "You need to specify the module name and optionally arguments.\n");
242 if (!(m = pa_module_load(c, name, pa_tokenizer_get(t, 2)))) {
243 pa_strbuf_puts(buf, "Module load failed.\n");
248 snprintf(txt, sizeof(txt), "Module successfully loaded, index: %u.\n", m->index);
249 pa_strbuf_puts(buf, txt);
254 static int pa_cli_command_unload(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
261 if (!(i = pa_tokenizer_get(t, 1))) {
262 pa_strbuf_puts(buf, "You need to specify the module index.\n");
266 index = (uint32_t) strtoul(i, &e, 10);
267 if (*e || !(m = pa_idxset_get_by_index(c->modules, index))) {
268 pa_strbuf_puts(buf, "Invalid module index.\n");
272 pa_module_unload_request(c, m);
276 static int pa_cli_command_sink_volume(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
279 struct pa_sink *sink;
282 if (!(n = pa_tokenizer_get(t, 1))) {
283 pa_strbuf_puts(buf, "You need to specify a sink either by its name or its index.\n");
287 if (!(v = pa_tokenizer_get(t, 2))) {
288 pa_strbuf_puts(buf, "You need to specify a volume >= 0. (0 is muted, 0x100 is normal volume)\n");
292 volume = strtol(v, &x, 0);
293 if (!x || *x != 0 || volume < 0) {
294 pa_strbuf_puts(buf, "Failed to parse volume.\n");
298 if (!(sink = pa_namereg_get(c, n, PA_NAMEREG_SINK, 1))) {
299 pa_strbuf_puts(buf, "No sink found by this name or index.\n");
303 pa_sink_set_volume(sink, (uint32_t) volume);
307 static int pa_cli_command_sink_input_volume(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
309 struct pa_sink_input *si;
314 if (!(n = pa_tokenizer_get(t, 1))) {
315 pa_strbuf_puts(buf, "You need to specify a sink input by its index.\n");
319 if ((index = parse_index(n)) == PA_IDXSET_INVALID) {
320 pa_strbuf_puts(buf, "Failed to parse index.\n");
324 if (!(v = pa_tokenizer_get(t, 2))) {
325 pa_strbuf_puts(buf, "You need to specify a volume >= 0. (0 is muted, 0x100 is normal volume)\n");
330 volume = strtol(v, &x, 0);
331 if (!x || *x != 0 || volume < 0) {
332 pa_strbuf_puts(buf, "Failed to parse volume.\n");
336 if (!(si = pa_idxset_get_by_index(c->sink_inputs, (uint32_t) index))) {
337 pa_strbuf_puts(buf, "No sink input found with this index.\n");
341 pa_sink_input_set_volume(si, (uint32_t) volume);
345 static int pa_cli_command_sink_default(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
349 if (!(n = pa_tokenizer_get(t, 1))) {
350 pa_strbuf_puts(buf, "You need to specify a sink either by its name or its index.\n");
354 pa_namereg_set_default(c, n, PA_NAMEREG_SINK);
358 static int pa_cli_command_source_default(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
362 if (!(n = pa_tokenizer_get(t, 1))) {
363 pa_strbuf_puts(buf, "You need to specify a source either by its name or its index.\n");
367 pa_namereg_set_default(c, n, PA_NAMEREG_SOURCE);
371 static int pa_cli_command_kill_client(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
373 struct pa_client *client;
377 if (!(n = pa_tokenizer_get(t, 1))) {
378 pa_strbuf_puts(buf, "You need to specify a client by its index.\n");
382 if ((index = parse_index(n)) == PA_IDXSET_INVALID) {
383 pa_strbuf_puts(buf, "Failed to parse index.\n");
387 if (!(client = pa_idxset_get_by_index(c->clients, index))) {
388 pa_strbuf_puts(buf, "No client found by this index.\n");
392 pa_client_kill(client);
396 static int pa_cli_command_kill_sink_input(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
398 struct pa_sink_input *sink_input;
402 if (!(n = pa_tokenizer_get(t, 1))) {
403 pa_strbuf_puts(buf, "You need to specify a sink input by its index.\n");
407 if ((index = parse_index(n)) == PA_IDXSET_INVALID) {
408 pa_strbuf_puts(buf, "Failed to parse index.\n");
412 if (!(sink_input = pa_idxset_get_by_index(c->sink_inputs, index))) {
413 pa_strbuf_puts(buf, "No sink input found by this index.\n");
417 pa_sink_input_kill(sink_input);
421 static int pa_cli_command_kill_source_output(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
423 struct pa_source_output *source_output;
427 if (!(n = pa_tokenizer_get(t, 1))) {
428 pa_strbuf_puts(buf, "You need to specify a source output by its index.\n");
432 if ((index = parse_index(n)) == PA_IDXSET_INVALID) {
433 pa_strbuf_puts(buf, "Failed to parse index.\n");
437 if (!(source_output = pa_idxset_get_by_index(c->source_outputs, index))) {
438 pa_strbuf_puts(buf, "No source output found by this index.\n");
442 pa_source_output_kill(source_output);
446 static int pa_cli_command_scache_list(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
449 s = pa_scache_list_to_string(c);
451 pa_strbuf_puts(buf, s);
456 static int pa_cli_command_scache_play(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
457 const char *n, *sink_name;
458 struct pa_sink *sink;
459 assert(c && t && buf && fail && verbose);
461 if (!(n = pa_tokenizer_get(t, 1)) || !(sink_name = pa_tokenizer_get(t, 2))) {
462 pa_strbuf_puts(buf, "You need to specify a sample name and a sink name.\n");
466 if (!(sink = pa_namereg_get(c, sink_name, PA_NAMEREG_SINK, 1))) {
467 pa_strbuf_puts(buf, "No sink by that name.\n");
471 if (pa_scache_play_item(c, n, sink, PA_VOLUME_NORM) < 0) {
472 pa_strbuf_puts(buf, "Failed to play sample.\n");
479 static int pa_cli_command_scache_remove(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
481 assert(c && t && buf && fail && verbose);
483 if (!(n = pa_tokenizer_get(t, 1))) {
484 pa_strbuf_puts(buf, "You need to specify a sample name.\n");
488 if (pa_scache_remove_item(c, n) < 0) {
489 pa_strbuf_puts(buf, "Failed to remove sample.\n");
496 static int pa_cli_command_scache_load(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
497 const char *fname, *n;
498 struct pa_memchunk chunk;
499 struct pa_sample_spec ss;
500 assert(c && t && buf && fail && verbose);
502 if (!(fname = pa_tokenizer_get(t, 1)) || !(n = pa_tokenizer_get(t, 2))) {
503 pa_strbuf_puts(buf, "You need to specify a file name and a sample name.\n");
507 if (pa_sound_file_load(fname, &ss, &chunk) < 0) {
508 pa_strbuf_puts(buf, "Failed to load sound file.\n");
512 pa_scache_add_item(c, n, &ss, &chunk, NULL);
513 pa_memblock_unref(chunk.memblock);
517 static int pa_cli_command_play_file(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
518 const char *fname, *sink_name;
519 struct pa_memchunk chunk;
520 struct pa_sample_spec ss;
521 struct pa_sink *sink;
523 assert(c && t && buf && fail && verbose);
525 if (!(fname = pa_tokenizer_get(t, 1)) || !(sink_name = pa_tokenizer_get(t, 2))) {
526 pa_strbuf_puts(buf, "You need to specify a file name and a sink name.\n");
530 if (!(sink = pa_namereg_get(c, sink_name, PA_NAMEREG_SINK, 1))) {
531 pa_strbuf_puts(buf, "No sink by that name.\n");
535 if (pa_sound_file_load(fname, &ss, &chunk) < 0) {
536 pa_strbuf_puts(buf, "Failed to load sound file.\n");
540 ret = pa_play_memchunk(sink, fname, &ss, &chunk, PA_VOLUME_NORM);
541 pa_memblock_unref(chunk.memblock);
545 static int pa_cli_command_autoload_add(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
546 const char *devname, *module;
547 assert(c && t && buf && fail && verbose);
549 if (!(devname = pa_tokenizer_get(t, 1)) || !(module = pa_tokenizer_get(t, 2))) {
550 pa_strbuf_puts(buf, "You need to specify a device name, a module name and optionally module arguments\n");
554 pa_autoload_add(c, devname, strstr(pa_tokenizer_get(t, 0), "sink") ? PA_NAMEREG_SINK : PA_NAMEREG_SOURCE, module, pa_tokenizer_get(t, 3));
558 static int pa_cli_command_autoload_remove(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
560 assert(c && t && buf && fail && verbose);
562 if (!(devname = pa_tokenizer_get(t, 1))) {
563 pa_strbuf_puts(buf, "You need to specify a device name\n");
567 if (pa_autoload_remove(c, devname, strstr(pa_tokenizer_get(t, 0), "sink") ? PA_NAMEREG_SINK : PA_NAMEREG_SOURCE) < 0) {
568 pa_strbuf_puts(buf, "Failed to remove autload entry\n");
575 static int pa_cli_command_autoload_list(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
578 s = pa_autoload_list_to_string(c);
580 pa_strbuf_puts(buf, s);
585 int pa_cli_command_execute_line(struct pa_core *c, const char *s, struct pa_strbuf *buf, int *fail, int *verbose) {
588 cs = s+strspn(s, whitespace);
590 if (*cs == '#' || !*cs)
592 else if (*cs == '.') {
593 static const char fail_meta[] = ".fail";
594 static const char nofail_meta[] = ".nofail";
595 static const char verbose_meta[] = ".verbose";
596 static const char noverbose_meta[] = ".noverbose";
598 if (!strcmp(cs, verbose_meta))
600 else if (!strcmp(cs, noverbose_meta))
602 else if (!strcmp(cs, fail_meta))
604 else if (!strcmp(cs, nofail_meta))
608 static const char include_meta[] = ".include";
609 l = strcspn(cs, whitespace);
611 if (l == sizeof(include_meta)-1 && !strncmp(cs, include_meta, l)) {
612 const char *filename = cs+l+strspn(cs+l, whitespace);
614 if (pa_cli_command_execute_file(c, filename, buf, fail, verbose) < 0)
615 if (*fail) return -1;
617 pa_strbuf_printf(buf, "Invalid meta command: %s\n", cs);
618 if (*fail) return -1;
622 const struct command*command;
626 l = strcspn(cs, whitespace);
628 for (command = commands; command->name; command++)
629 if (strlen(command->name) == l && !strncmp(cs, command->name, l)) {
631 struct pa_tokenizer *t = pa_tokenizer_new(cs, command->args);
633 ret = command->proc(c, t, buf, fail, verbose);
634 pa_tokenizer_free(t);
637 if (ret < 0 && *fail)
644 pa_strbuf_printf(buf, "Unknown command: %s\n", cs);
653 int pa_cli_command_execute_file(struct pa_core *c, const char *fn, struct pa_strbuf *buf, int *fail, int *verbose) {
657 assert(c && fn && buf);
659 if (!(f = fopen(fn, "r"))) {
660 pa_strbuf_printf(buf, "open('%s') failed: %s\n", fn, strerror(errno));
667 pa_strbuf_printf(buf, "Executing file: '%s'\n", fn);
669 while (fgets(line, sizeof(line), f)) {
670 char *e = line + strcspn(line, linebreak);
673 if (pa_cli_command_execute_line(c, line, buf, fail, verbose) < 0 && *fail)
678 pa_strbuf_printf(buf, "Executed file: '%s'\n", fn);
689 int pa_cli_command_execute(struct pa_core *c, const char *s, struct pa_strbuf *buf, int *fail, int *verbose) {
691 assert(c && s && buf && fail && verbose);
695 size_t l = strcspn(p, linebreak);
696 char *line = pa_xstrndup(p, l);
698 if (pa_cli_command_execute_line(c, line, buf, fail, verbose) < 0&& *fail) {
705 p += strspn(p, linebreak);