2 * This file is part of DisOrder.
3 * Copyright (C) 2004-2008 Richard Kettlewell
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 /** @file clients/disorder.c
19 * @brief Command-line client
25 #include <sys/types.h>
26 #include <sys/socket.h>
36 #include "configuration.h"
49 #include "authorize.h"
52 #include "dateparse.h"
54 static disorder_client
*client
;
56 static const struct option options
[] = {
57 { "help", no_argument
, 0, 'h' },
58 { "version", no_argument
, 0, 'V' },
59 { "config", required_argument
, 0, 'c' },
60 { "debug", no_argument
, 0, 'd' },
61 { "local", no_argument
, 0, 'l' },
62 { "no-per-user-config", no_argument
, 0, 'N' },
63 { "help-commands", no_argument
, 0, 'H' },
64 { "user", required_argument
, 0, 'u' },
65 { "password", required_argument
, 0, 'p' },
69 /* display usage message and terminate */
70 static void help(void) {
72 " disorder [OPTIONS] COMMAND ...\n"
74 " --help, -h Display usage message\n"
75 " --help-commands, -H List commands\n"
76 " --version, -V Display version number\n"
77 " --config PATH, -c PATH Set configuration file\n"
78 " --local, -l Force connection to local server\n"
79 " --debug, -d Turn on debugging\n");
84 static disorder_client
*getclient(void) {
86 if(!(client
= disorder_new(1))) exit(EXIT_FAILURE
);
87 if(disorder_connect(client
)) exit(EXIT_FAILURE
);
92 static void cf_version(char attribute((unused
)) **argv
) {
95 if(disorder_version(getclient(), &v
)) exit(EXIT_FAILURE
);
96 xprintf("%s\n", nullcheck(utf82mb(v
)));
99 static void print_queue_entry(const struct queue_entry
*q
) {
100 if(q
->track
) xprintf("track %s\n", nullcheck(utf82mb(q
->track
)));
101 if(q
->id
) xprintf(" id %s\n", nullcheck(utf82mb(q
->id
)));
102 if(q
->submitter
) xprintf(" submitted by %s at %s",
103 nullcheck(utf82mb(q
->submitter
)), ctime(&q
->when
));
104 if(q
->played
) xprintf(" played at %s", ctime(&q
->played
));
105 if(q
->state
== playing_started
106 || q
->state
== playing_paused
) xprintf(" %lds so far", q
->sofar
);
107 else if(q
->expected
) xprintf(" might start at %s", ctime(&q
->expected
));
108 if(q
->scratched
) xprintf(" scratched by %s\n",
109 nullcheck(utf82mb(q
->scratched
)));
110 else xprintf(" %s\n", playing_states
[q
->state
]);
111 if(q
->wstat
) xprintf(" %s\n", wstat(q
->wstat
));
114 static void cf_playing(char attribute((unused
)) **argv
) {
115 struct queue_entry
*q
;
117 if(disorder_playing(getclient(), &q
)) exit(EXIT_FAILURE
);
119 print_queue_entry(q
);
121 xprintf("nothing\n");
124 static void cf_play(char **argv
) {
126 if(disorder_play(getclient(), *argv
++)) exit(EXIT_FAILURE
);
129 static void cf_remove(char **argv
) {
130 if(disorder_remove(getclient(), argv
[0])) exit(EXIT_FAILURE
);
133 static void cf_disable(char attribute((unused
)) **argv
) {
134 if(disorder_disable(getclient())) exit(EXIT_FAILURE
);
137 static void cf_enable(char attribute((unused
)) **argv
) {
138 if(disorder_enable(getclient())) exit(EXIT_FAILURE
);
141 static void cf_scratch(char **argv
) {
142 if(disorder_scratch(getclient(), argv
[0])) exit(EXIT_FAILURE
);
145 static void cf_shutdown(char attribute((unused
)) **argv
) {
146 if(disorder_shutdown(getclient())) exit(EXIT_FAILURE
);
149 static void cf_reconfigure(char attribute((unused
)) **argv
) {
150 /* Re-check configuration for server */
151 if(config_read(1)) fatal(0, "cannot read configuration");
152 if(disorder_reconfigure(getclient())) exit(EXIT_FAILURE
);
155 static void cf_rescan(char attribute((unused
)) **argv
) {
156 if(disorder_rescan(getclient())) exit(EXIT_FAILURE
);
159 static void cf_somequeue(int (*fn
)(disorder_client
*c
,
160 struct queue_entry
**qp
)) {
161 struct queue_entry
*q
;
163 if(fn(getclient(), &q
)) exit(EXIT_FAILURE
);
165 print_queue_entry(q
);
170 static void cf_recent(char attribute((unused
)) **argv
) {
171 cf_somequeue(disorder_recent
);
174 static void cf_queue(char attribute((unused
)) **argv
) {
175 cf_somequeue(disorder_queue
);
178 static void cf_quack(char attribute((unused
)) **argv
) {
180 " .------------------.\n"
181 " | Naath is a babe! |\n"
182 " `---------+--------'\n"
186 "~~~~~~~~~~~~~~~~~~~~~~\n"
190 static void cf_somelist(char **argv
,
191 int (*fn
)(disorder_client
*c
,
192 const char *arg
, const char *re
,
193 char ***vecp
, int *nvecp
)) {
198 re
= xstrdup(argv
[1] + 1);
201 if(fn(getclient(), argv
[0], re
, &vec
, 0)) exit(EXIT_FAILURE
);
203 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
206 static int isarg_regexp(const char *s
) {
210 static void cf_dirs(char **argv
) {
211 cf_somelist(argv
, disorder_directories
);
214 static void cf_files(char **argv
) {
215 cf_somelist(argv
, disorder_files
);
218 static void cf_allfiles(char **argv
) {
219 cf_somelist(argv
, disorder_allfiles
);
222 static void cf_get(char **argv
) {
225 if(disorder_get(getclient(), argv
[0], argv
[1], &value
)) exit(EXIT_FAILURE
);
226 xprintf("%s\n", nullcheck(utf82mb(value
)));
229 static void cf_length(char **argv
) {
232 if(disorder_length(getclient(), argv
[0], &length
)) exit(EXIT_FAILURE
);
233 xprintf("%ld\n", length
);
236 static void cf_set(char **argv
) {
237 if(disorder_set(getclient(), argv
[0], argv
[1], argv
[2])) exit(EXIT_FAILURE
);
240 static void cf_unset(char **argv
) {
241 if(disorder_unset(getclient(), argv
[0], argv
[1])) exit(EXIT_FAILURE
);
244 static void cf_prefs(char **argv
) {
247 if(disorder_prefs(getclient(), argv
[0], &k
)) exit(EXIT_FAILURE
);
248 for(; k
; k
= k
->next
)
250 nullcheck(utf82mb(k
->name
)), nullcheck(utf82mb(k
->value
)));
253 static void cf_search(char **argv
) {
257 if(disorder_search(getclient(), *argv
, &results
, &nresults
)) exit(EXIT_FAILURE
);
258 for(n
= 0; n
< nresults
; ++n
)
259 xprintf("%s\n", nullcheck(utf82mb(results
[n
])));
262 static void cf_random_disable(char attribute((unused
)) **argv
) {
263 if(disorder_random_disable(getclient())) exit(EXIT_FAILURE
);
266 static void cf_random_enable(char attribute((unused
)) **argv
) {
267 if(disorder_random_enable(getclient())) exit(EXIT_FAILURE
);
270 static void cf_stats(char attribute((unused
)) **argv
) {
273 if(disorder_stats(getclient(), &vec
, 0)) exit(EXIT_FAILURE
);
275 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
278 static void cf_get_volume(char attribute((unused
)) **argv
) {
281 if(disorder_get_volume(getclient(), &l
, &r
)) exit(EXIT_FAILURE
);
282 xprintf("%d %d\n", l
, r
);
285 static void cf_set_volume(char **argv
) {
286 if(disorder_set_volume(getclient(), atoi(argv
[0]), atoi(argv
[1]))) exit(EXIT_FAILURE
);
289 static void cf_log(char attribute((unused
)) **argv
) {
290 if(disorder_log(getclient(), sink_stdio("stdout", stdout
))) exit(EXIT_FAILURE
);
293 static void cf_move(char **argv
) {
297 if((e
= xstrtol(&n
, argv
[1], 0, 10)))
298 fatal(e
, "cannot convert '%s'", argv
[1]);
299 if(n
> INT_MAX
|| n
< INT_MIN
)
300 fatal(e
, "%ld out of range", n
);
301 if(disorder_move(getclient(), argv
[0], (int)n
)) exit(EXIT_FAILURE
);
304 static void cf_part(char **argv
) {
307 if(disorder_part(getclient(), &s
, argv
[0], argv
[1], argv
[2])) exit(EXIT_FAILURE
);
308 xprintf("%s\n", nullcheck(utf82mb(s
)));
311 static int isarg_filename(const char *s
) {
315 static void cf_authorize(char **argv
) {
316 authorize(getclient(), argv
[0], argv
[1]);
319 static void cf_resolve(char **argv
) {
322 if(disorder_resolve(getclient(), &track
, argv
[0])) exit(EXIT_FAILURE
);
323 xprintf("%s\n", nullcheck(utf82mb(track
)));
326 static void cf_pause(char attribute((unused
)) **argv
) {
327 if(disorder_pause(getclient())) exit(EXIT_FAILURE
);
330 static void cf_resume(char attribute((unused
)) **argv
) {
331 if(disorder_resume(getclient())) exit(EXIT_FAILURE
);
334 static void cf_tags(char attribute((unused
)) **argv
) {
337 if(disorder_tags(getclient(), &vec
, 0)) exit(EXIT_FAILURE
);
339 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
342 static void cf_users(char attribute((unused
)) **argv
) {
345 if(disorder_users(getclient(), &vec
, 0)) exit(EXIT_FAILURE
);
347 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
350 static void cf_get_global(char **argv
) {
353 if(disorder_get_global(getclient(), argv
[0], &value
)) exit(EXIT_FAILURE
);
354 xprintf("%s\n", nullcheck(utf82mb(value
)));
357 static void cf_set_global(char **argv
) {
358 if(disorder_set_global(getclient(), argv
[0], argv
[1])) exit(EXIT_FAILURE
);
361 static void cf_unset_global(char **argv
) {
362 if(disorder_unset_global(getclient(), argv
[0])) exit(EXIT_FAILURE
);
365 static int isarg_integer(const char *s
) {
368 if(!isdigit((unsigned char)*s
))
375 static void cf_new(char **argv
) {
378 if(disorder_new_tracks(getclient(), &vec
, 0, argv
[0] ?
atoi(argv
[0]) : 0))
381 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
384 static void cf_rtp_address(char attribute((unused
)) **argv
) {
385 char *address
, *port
;
387 if(disorder_rtp_address(getclient(), &address
, &port
)) exit(EXIT_FAILURE
);
388 xprintf("address: %s\nport: %s\n", address
, port
);
391 static int isarg_rights(const char *arg
) {
392 return strchr(arg
, ',') || !parse_rights(arg
, 0, 0);
395 static void cf_adduser(char **argv
) {
396 if(disorder_adduser(getclient(), argv
[0], argv
[1], argv
[2]))
400 static void cf_deluser(char **argv
) {
401 if(disorder_deluser(getclient(), argv
[0]))
405 static void cf_edituser(char **argv
) {
406 if(disorder_edituser(getclient(), argv
[0], argv
[1], argv
[2]))
410 static void cf_userinfo(char **argv
) {
413 if(disorder_userinfo(getclient(), argv
[0], argv
[1], &s
))
415 xprintf("%s\n", nullcheck(utf82mb(s
)));
418 static int isarg_option(const char *arg
) {
419 return arg
[0] == '-';
422 static int argvlen(char **argv
) {
430 static const struct option setup_guest_options
[] = {
431 { "help", no_argument
, 0, 'h' },
432 { "online-registration", no_argument
, 0, 'r' },
433 { "no-online-registration", no_argument
, 0, 'R' },
437 static void help_setup_guest(void) {
439 " disorder setup-guest [OPTIONS]\n"
441 " --help, -h Display usage message\n"
442 " --online-registration Enable online registration (default)\n"
443 " --no-online-registration Disable online registration\n");
448 static void cf_setup_guest(char **argv
) {
449 int n
, online_registration
= 1;
451 while((n
= getopt_long(argvlen(argv
) + 1, argv
- 1,
452 "hrR", setup_guest_options
, 0)) >= 0) {
454 case 'h': help_setup_guest();
455 case 'r': online_registration
= 1; break;
456 case 'R': online_registration
= 0; break;
457 default: fatal(0, "invalid option");
460 if(online_registration
&& !config
->mail_sender
)
461 fatal(0, "you MUST set mail_sender if you want online registration");
462 if(disorder_adduser(getclient(), "guest", "",
463 online_registration ?
"read,register" : "read"))
467 struct scheduled_event
{
469 struct kvp
*actiondata
;
473 static int compare_event(const void *av
, const void *bv
) {
474 struct scheduled_event
*a
= (void *)av
, *b
= (void *)bv
;
476 /* Primary sort key is the trigger time */
477 if(a
->when
< b
->when
)
479 else if(a
->when
> b
->when
)
481 /* For events that go off at the same time just sort by ID */
482 return strcmp(a
->id
, b
->id
);
485 static void cf_schedule_list(char attribute((unused
)) **argv
) {
488 struct scheduled_event
*events
;
490 const char *action
, *key
, *value
, *priority
;
493 /* Get all known events */
494 if(disorder_schedule_list(getclient(), &ids
, &nids
))
496 events
= xcalloc(nids
, sizeof *events
);
497 for(n
= 0; n
< nids
; ++n
) {
498 events
[n
].id
= ids
[n
];
499 if(disorder_schedule_get(getclient(), ids
[n
], &events
[n
].actiondata
))
501 events
[n
].when
= atoll(kvp_get(events
[n
].actiondata
, "when"));
503 /* Sort by trigger time */
504 qsort(events
, nids
, sizeof *events
, compare_event
);
506 for(n
= 0; n
< nids
; ++n
) {
507 strftime(tb
, sizeof tb
, "%Y-%m-%d %H:%M:%S %Z", localtime(&events
[n
].when
));
508 action
= kvp_get(events
[n
].actiondata
, "action");
509 priority
= kvp_get(events
[n
].actiondata
, "priority");
510 if(!strcmp(priority
, "junk"))
512 else if(!strcmp(priority
, "normal"))
516 xprintf("%11s %-25s %c %-8s %s",
517 events
[n
].id
, tb
, prichar
, kvp_get(events
[n
].actiondata
, "who"),
519 if(!strcmp(action
, "play"))
521 nullcheck(utf82mb(kvp_get(events
[n
].actiondata
, "track"))));
522 else if(!strcmp(action
, "set-global")) {
523 key
= kvp_get(events
[n
].actiondata
, "key");
524 value
= kvp_get(events
[n
].actiondata
, "value");
527 nullcheck(utf82mb(key
)),
528 nullcheck(utf82mb(value
)));
531 nullcheck(utf82mb(key
)));
537 static void cf_schedule_del(char **argv
) {
538 if(disorder_schedule_del(getclient(), argv
[0]))
542 static void cf_schedule_play(char **argv
) {
543 if(disorder_schedule_add(getclient(),
551 static void cf_schedule_set_global(char **argv
) {
552 if(disorder_schedule_add(getclient(),
561 static void cf_schedule_unset_global(char **argv
) {
562 if(disorder_schedule_add(getclient(),
571 static const struct command
{
575 int (*isarg
)(const char *);
576 const char *argstr
, *desc
;
578 { "adduser", 2, 3, cf_adduser
, isarg_rights
, "USERNAME PASSWORD [RIGHTS]",
579 "Create a new user" },
580 { "allfiles", 1, 2, cf_allfiles
, isarg_regexp
, "DIR [~REGEXP]",
581 "List all files and directories in DIR" },
582 { "authorize", 1, 2, cf_authorize
, isarg_rights
, "USERNAME [RIGHTS]",
583 "Authorize user USERNAME to connect" },
584 { "deluser", 1, 1, cf_deluser
, 0, "USERNAME",
585 "Delete user USERNAME" },
586 { "dirs", 1, 2, cf_dirs
, isarg_regexp
, "DIR [~REGEXP]",
587 "List directories in DIR" },
588 { "disable", 0, 0, cf_disable
, 0, "",
590 { "disable-random", 0, 0, cf_random_disable
, 0, "",
591 "Disable random play" },
592 { "edituser", 3, 3, cf_edituser
, 0, "USERNAME PROPERTY VALUE",
593 "Set a property of user USERNAME" },
594 { "enable", 0, 0, cf_enable
, 0, "",
596 { "enable-random", 0, 0, cf_random_enable
, 0, "",
597 "Enable random play" },
598 { "files", 1, 2, cf_files
, isarg_regexp
, "DIR [~REGEXP]",
599 "List files in DIR" },
600 { "get", 2, 2, cf_get
, 0, "TRACK NAME",
601 "Get a preference value" },
602 { "get-global", 1, 1, cf_get_global
, 0, "NAME",
603 "Get a global preference value" },
604 { "get-volume", 0, 0, cf_get_volume
, 0, "",
605 "Get the current volume" },
606 { "length", 1, 1, cf_length
, 0, "TRACK",
607 "Get the length of TRACK in seconds" },
608 { "log", 0, 0, cf_log
, 0, "",
609 "Copy event log to stdout" },
610 { "move", 2, 2, cf_move
, 0, "TRACK DELTA",
611 "Move a track in the queue" },
612 { "new", 0, 1, cf_new
, isarg_integer
, "[MAX]",
613 "Get the most recently added MAX tracks" },
614 { "part", 3, 3, cf_part
, 0, "TRACK CONTEXT PART",
615 "Find a track name part" },
616 { "pause", 0, 0, cf_pause
, 0, "",
617 "Pause the currently playing track" },
618 { "play", 1, INT_MAX
, cf_play
, isarg_filename
, "TRACKS...",
619 "Add TRACKS to the end of the queue" },
620 { "playing", 0, 0, cf_playing
, 0, "",
621 "Report the playing track" },
622 { "prefs", 1, 1, cf_prefs
, 0, "TRACK",
623 "Display all the preferences for TRACK" },
624 { "quack", 0, 0, cf_quack
, 0, 0, 0 },
625 { "queue", 0, 0, cf_queue
, 0, "",
626 "Display the current queue" },
627 { "random-disable", 0, 0, cf_random_disable
, 0, "",
628 "Disable random play" },
629 { "random-enable", 0, 0, cf_random_enable
, 0, "",
630 "Enable random play" },
631 { "recent", 0, 0, cf_recent
, 0, "",
632 "Display recently played track" },
633 { "reconfigure", 0, 0, cf_reconfigure
, 0, "",
634 "Reconfigure the daemon" },
635 { "remove", 1, 1, cf_remove
, 0, "TRACK",
636 "Remove a track from the queue" },
637 { "rescan", 0, 0, cf_rescan
, 0, "",
638 "Rescan for new tracks" },
639 { "resolve", 1, 1, cf_resolve
, 0, "TRACK",
640 "Resolve alias for TRACK" },
641 { "resume", 0, 0, cf_resume
, 0, "",
642 "Resume after a pause" },
643 { "rtp-address", 0, 0, cf_rtp_address
, 0, "",
644 "Report server's broadcast address" },
645 { "schedule-del", 1, 1, cf_schedule_del
, 0, "EVENT",
646 "Delete a scheduled event" },
647 { "schedule-list", 0, 0, cf_schedule_list
, 0, "",
648 "List scheduled events" },
649 { "schedule-play", 3, 3, cf_schedule_play
, 0, "WHEN PRI TRACK",
650 "Play TRACK later" },
651 { "schedule-set-global", 4, 4, cf_schedule_set_global
, 0, "WHEN PRI NAME VAL",
652 "Set a global preference later" },
653 { "schedule-unset-global", 3, 3, cf_schedule_unset_global
, 0, "WHEN PRI NAME",
654 "Unset a global preference later" },
655 { "scratch", 0, 0, cf_scratch
, 0, "",
656 "Scratch the currently playing track" },
657 { "scratch-id", 1, 1, cf_scratch
, 0, "ID",
658 "Scratch the currently playing track" },
659 { "search", 1, 1, cf_search
, 0, "WORDS",
660 "Display tracks matching all the words" },
661 { "set", 3, 3, cf_set
, 0, "TRACK NAME VALUE",
662 "Set a preference value" },
663 { "set-global", 2, 2, cf_set_global
, 0, "NAME VALUE",
664 "Set a global preference value" },
665 { "set-volume", 2, 2, cf_set_volume
, 0, "LEFT RIGHT",
667 { "setup-guest", 0, INT_MAX
, cf_setup_guest
, isarg_option
, "[OPTIONS]",
668 "Create the guest login" },
669 { "shutdown", 0, 0, cf_shutdown
, 0, "",
670 "Shut down the daemon" },
671 { "stats", 0, 0, cf_stats
, 0, "",
672 "Display server statistics" },
673 { "tags", 0, 0, cf_tags
, 0, "",
675 { "unset", 2, 2, cf_unset
, 0, "TRACK NAME",
676 "Unset a preference" },
677 { "unset-global", 1, 1, cf_unset_global
, 0, "NAME",
678 "Unset a global preference" },
679 { "userinfo", 2, 2, cf_userinfo
, 0, "USERNAME PROPERTY",
680 "Get a property of a user" },
681 { "users", 0, 0, cf_users
, 0, "",
683 { "version", 0, 0, cf_version
, 0, "",
684 "Display the server version" },
687 static void help_commands(void) {
688 unsigned n
, max
= 0, l
;
690 xprintf("Command summary:\n");
691 for(n
= 0; n
< sizeof commands
/ sizeof *commands
; ++n
) {
692 if(!commands
[n
].desc
) continue;
693 l
= strlen(commands
[n
].name
);
694 if(*commands
[n
].argstr
)
695 l
+= strlen(commands
[n
].argstr
) + 1;
699 for(n
= 0; n
< sizeof commands
/ sizeof *commands
; ++n
) {
700 if(!commands
[n
].desc
) continue;
701 l
= strlen(commands
[n
].name
);
702 if(*commands
[n
].argstr
)
703 l
+= strlen(commands
[n
].argstr
) + 1;
704 xprintf(" %s%s%s%*s %s\n", commands
[n
].name
,
705 *commands
[n
].argstr ?
" " : "",
714 int main(int argc
, char **argv
) {
715 int n
, i
, j
, local
= 0;
718 const char *user
= 0, *password
= 0;
721 /* garbage-collect PCRE's memory */
722 pcre_malloc
= xmalloc
;
724 if(!setlocale(LC_CTYPE
, "")) fatal(errno
, "error calling setlocale");
725 if(!setlocale(LC_TIME
, "")) fatal(errno
, "error calling setlocale");
726 while((n
= getopt_long(argc
, argv
, "+hVc:dHlNu:p:", options
, 0)) >= 0) {
729 case 'H': help_commands();
730 case 'V': version("disorder");
731 case 'c': configfile
= optarg
; break;
732 case 'd': debugging
= 1; break;
733 case 'l': local
= 1; break;
734 case 'N': config_per_user
= 0; break;
735 case 'u': user
= optarg
; break;
736 case 'p': password
= optarg
; break;
737 default: fatal(0, "invalid option");
740 if(config_read(0)) fatal(0, "cannot read configuration");
742 config
->username
= user
;
743 config
->password
= 0;
746 config
->password
= password
;
748 config
->connect
.n
= 0;
750 optind
= 1; /* for subsequent getopt calls */
751 /* accumulate command args */
753 if((i
= TABLE_FIND(commands
, name
, argv
[n
])) < 0)
754 fatal(0, "unknown command '%s'", argv
[n
]);
755 if(n
+ commands
[i
].min
>= argc
)
756 fatal(0, "missing arguments to '%s'", argv
[n
]);
758 /* Include the command name in the args, but at element -1, for
759 * the benefit of subcommand getopt calls */
760 vector_append(&args
, argv
[n
]);
762 for(j
= 0; j
< commands
[i
].min
; ++j
)
763 vector_append(&args
, nullcheck(mb2utf8(argv
[n
+ j
])));
764 for(; j
< commands
[i
].max
766 && commands
[i
].isarg(argv
[n
+ j
]); ++j
)
767 vector_append(&args
, nullcheck(mb2utf8(argv
[n
+ j
])));
768 vector_terminate(&args
);
769 commands
[i
].fn(args
.vec
+ 1);
772 if(client
&& disorder_close(client
)) exit(EXIT_FAILURE
);
773 if(fclose(stdout
) < 0) fatal(errno
, "error closing stdout");