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 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #include <sys/types.h>
26 #include <sys/socket.h>
40 #include "configuration.h"
54 #include "authorize.h"
58 static disorder_client
*client
;
60 static const struct option options
[] = {
61 { "help", no_argument
, 0, 'h' },
62 { "version", no_argument
, 0, 'V' },
63 { "config", required_argument
, 0, 'c' },
64 { "debug", no_argument
, 0, 'd' },
65 { "local", no_argument
, 0, 'l' },
66 { "no-per-user-config", no_argument
, 0, 'N' },
67 { "help-commands", no_argument
, 0, 'H' },
68 { "user", required_argument
, 0, 'u' },
69 { "password", required_argument
, 0, 'p' },
73 /* display usage message and terminate */
74 static void help(void) {
76 " disorder [OPTIONS] COMMAND ...\n"
78 " --help, -h Display usage message\n"
79 " --help-commands, -H List commands\n"
80 " --version, -V Display version number\n"
81 " --config PATH, -c PATH Set configuration file\n"
82 " --local, -l Force connection to local server\n"
83 " --debug, -d Turn on debugging\n");
88 static disorder_client
*getclient(void) {
90 if(!(client
= disorder_new(1))) exit(EXIT_FAILURE
);
91 if(disorder_connect(client
)) exit(EXIT_FAILURE
);
96 static void cf_version(char attribute((unused
)) **argv
) {
99 if(disorder_version(getclient(), &v
)) exit(EXIT_FAILURE
);
100 xprintf("%s\n", nullcheck(utf82mb(v
)));
103 static void print_queue_entry(const struct queue_entry
*q
) {
104 if(q
->track
) xprintf("track %s\n", nullcheck(utf82mb(q
->track
)));
105 if(q
->id
) xprintf(" id %s\n", nullcheck(utf82mb(q
->id
)));
106 if(q
->submitter
) xprintf(" submitted by %s at %s",
107 nullcheck(utf82mb(q
->submitter
)), ctime(&q
->when
));
108 if(q
->played
) xprintf(" played at %s", ctime(&q
->played
));
109 if(q
->state
== playing_started
110 || q
->state
== playing_paused
) xprintf(" %lds so far", q
->sofar
);
111 else if(q
->expected
) xprintf(" might start at %s", ctime(&q
->expected
));
112 if(q
->scratched
) xprintf(" scratched by %s\n",
113 nullcheck(utf82mb(q
->scratched
)));
114 else xprintf(" %s\n", playing_states
[q
->state
]);
115 if(q
->wstat
) xprintf(" %s\n", wstat(q
->wstat
));
118 static void cf_playing(char attribute((unused
)) **argv
) {
119 struct queue_entry
*q
;
121 if(disorder_playing(getclient(), &q
)) exit(EXIT_FAILURE
);
123 print_queue_entry(q
);
125 xprintf("nothing\n");
128 static void cf_play(char **argv
) {
130 if(disorder_play(getclient(), *argv
++)) exit(EXIT_FAILURE
);
133 static void cf_remove(char **argv
) {
134 if(disorder_remove(getclient(), argv
[0])) exit(EXIT_FAILURE
);
137 static void cf_disable(char attribute((unused
)) **argv
) {
138 if(disorder_disable(getclient())) exit(EXIT_FAILURE
);
141 static void cf_enable(char attribute((unused
)) **argv
) {
142 if(disorder_enable(getclient())) exit(EXIT_FAILURE
);
145 static void cf_scratch(char **argv
) {
146 if(disorder_scratch(getclient(), argv
[0])) exit(EXIT_FAILURE
);
149 static void cf_shutdown(char attribute((unused
)) **argv
) {
150 if(disorder_shutdown(getclient())) exit(EXIT_FAILURE
);
153 static void cf_reconfigure(char attribute((unused
)) **argv
) {
154 /* Re-check configuration for server */
155 if(config_read(1)) fatal(0, "cannot read configuration");
156 if(disorder_reconfigure(getclient())) exit(EXIT_FAILURE
);
159 static void cf_rescan(char attribute((unused
)) **argv
) {
160 if(disorder_rescan(getclient())) exit(EXIT_FAILURE
);
163 static void cf_somequeue(int (*fn
)(disorder_client
*c
,
164 struct queue_entry
**qp
)) {
165 struct queue_entry
*q
;
167 if(fn(getclient(), &q
)) exit(EXIT_FAILURE
);
169 print_queue_entry(q
);
174 static void cf_recent(char attribute((unused
)) **argv
) {
175 cf_somequeue(disorder_recent
);
178 static void cf_queue(char attribute((unused
)) **argv
) {
179 cf_somequeue(disorder_queue
);
182 static void cf_quack(char attribute((unused
)) **argv
) {
184 " .------------------.\n"
185 " | Naath is a babe! |\n"
186 " `---------+--------'\n"
190 "~~~~~~~~~~~~~~~~~~~~~~\n"
194 static void cf_somelist(char **argv
,
195 int (*fn
)(disorder_client
*c
,
196 const char *arg
, const char *re
,
197 char ***vecp
, int *nvecp
)) {
202 re
= xstrdup(argv
[1] + 1);
205 if(fn(getclient(), argv
[0], re
, &vec
, 0)) exit(EXIT_FAILURE
);
207 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
210 static int isarg_regexp(const char *s
) {
214 static void cf_dirs(char **argv
) {
215 cf_somelist(argv
, disorder_directories
);
218 static void cf_files(char **argv
) {
219 cf_somelist(argv
, disorder_files
);
222 static void cf_allfiles(char **argv
) {
223 cf_somelist(argv
, disorder_allfiles
);
226 static void cf_get(char **argv
) {
229 if(disorder_get(getclient(), argv
[0], argv
[1], &value
)) exit(EXIT_FAILURE
);
230 xprintf("%s\n", nullcheck(utf82mb(value
)));
233 static void cf_length(char **argv
) {
236 if(disorder_length(getclient(), argv
[0], &length
)) exit(EXIT_FAILURE
);
237 xprintf("%ld\n", length
);
240 static void cf_set(char **argv
) {
241 if(disorder_set(getclient(), argv
[0], argv
[1], argv
[2])) exit(EXIT_FAILURE
);
244 static void cf_unset(char **argv
) {
245 if(disorder_unset(getclient(), argv
[0], argv
[1])) exit(EXIT_FAILURE
);
248 static void cf_prefs(char **argv
) {
251 if(disorder_prefs(getclient(), argv
[0], &k
)) exit(EXIT_FAILURE
);
252 for(; k
; k
= k
->next
)
254 nullcheck(utf82mb(k
->name
)), nullcheck(utf82mb(k
->value
)));
257 static void cf_search(char **argv
) {
261 if(disorder_search(getclient(), *argv
, &results
, &nresults
)) exit(EXIT_FAILURE
);
262 for(n
= 0; n
< nresults
; ++n
)
263 xprintf("%s\n", nullcheck(utf82mb(results
[n
])));
266 static void cf_random_disable(char attribute((unused
)) **argv
) {
267 if(disorder_random_disable(getclient())) exit(EXIT_FAILURE
);
270 static void cf_random_enable(char attribute((unused
)) **argv
) {
271 if(disorder_random_enable(getclient())) exit(EXIT_FAILURE
);
274 static void cf_stats(char attribute((unused
)) **argv
) {
277 if(disorder_stats(getclient(), &vec
, 0)) exit(EXIT_FAILURE
);
279 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
282 static void cf_get_volume(char attribute((unused
)) **argv
) {
285 if(disorder_get_volume(getclient(), &l
, &r
)) exit(EXIT_FAILURE
);
286 xprintf("%d %d\n", l
, r
);
289 static void cf_set_volume(char **argv
) {
290 if(disorder_set_volume(getclient(), atoi(argv
[0]), atoi(argv
[1]))) exit(EXIT_FAILURE
);
293 static void cf_log(char attribute((unused
)) **argv
) {
294 if(disorder_log(getclient(), sink_stdio("stdout", stdout
))) exit(EXIT_FAILURE
);
297 static void cf_move(char **argv
) {
301 if((e
= xstrtol(&n
, argv
[1], 0, 10)))
302 fatal(e
, "cannot convert '%s'", argv
[1]);
303 if(n
> INT_MAX
|| n
< INT_MIN
)
304 fatal(e
, "%ld out of range", n
);
305 if(disorder_move(getclient(), argv
[0], (int)n
)) exit(EXIT_FAILURE
);
308 static void cf_part(char **argv
) {
311 if(disorder_part(getclient(), &s
, argv
[0], argv
[1], argv
[2])) exit(EXIT_FAILURE
);
312 xprintf("%s\n", nullcheck(utf82mb(s
)));
315 static int isarg_filename(const char *s
) {
319 static void cf_authorize(char **argv
) {
320 authorize(getclient(), argv
[0], argv
[1]);
323 static void cf_resolve(char **argv
) {
326 if(disorder_resolve(getclient(), &track
, argv
[0])) exit(EXIT_FAILURE
);
327 xprintf("%s\n", nullcheck(utf82mb(track
)));
330 static void cf_pause(char attribute((unused
)) **argv
) {
331 if(disorder_pause(getclient())) exit(EXIT_FAILURE
);
334 static void cf_resume(char attribute((unused
)) **argv
) {
335 if(disorder_resume(getclient())) exit(EXIT_FAILURE
);
338 static void cf_tags(char attribute((unused
)) **argv
) {
341 if(disorder_tags(getclient(), &vec
, 0)) exit(EXIT_FAILURE
);
343 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
346 static void cf_users(char attribute((unused
)) **argv
) {
349 if(disorder_users(getclient(), &vec
, 0)) exit(EXIT_FAILURE
);
351 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
354 static void cf_get_global(char **argv
) {
357 if(disorder_get_global(getclient(), argv
[0], &value
)) exit(EXIT_FAILURE
);
358 xprintf("%s\n", nullcheck(utf82mb(value
)));
361 static void cf_set_global(char **argv
) {
362 if(disorder_set_global(getclient(), argv
[0], argv
[1])) exit(EXIT_FAILURE
);
365 static void cf_unset_global(char **argv
) {
366 if(disorder_unset_global(getclient(), argv
[0])) exit(EXIT_FAILURE
);
369 static int isarg_integer(const char *s
) {
372 if(!isdigit((unsigned char)*s
))
379 static void cf_new(char **argv
) {
382 if(disorder_new_tracks(getclient(), &vec
, 0, argv
[0] ?
atoi(argv
[0]) : 0))
385 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
388 static void cf_rtp_address(char attribute((unused
)) **argv
) {
389 char *address
, *port
;
391 if(disorder_rtp_address(getclient(), &address
, &port
)) exit(EXIT_FAILURE
);
392 xprintf("address: %s\nport: %s\n", address
, port
);
395 static int isarg_rights(const char *arg
) {
396 return strchr(arg
, ',') || !parse_rights(arg
, 0, 0);
399 static void cf_adduser(char **argv
) {
400 if(disorder_adduser(getclient(), argv
[0], argv
[1], argv
[2]))
404 static void cf_deluser(char **argv
) {
405 if(disorder_deluser(getclient(), argv
[0]))
409 static void cf_edituser(char **argv
) {
410 if(disorder_edituser(getclient(), argv
[0], argv
[1], argv
[2]))
414 static void cf_userinfo(char **argv
) {
417 if(disorder_userinfo(getclient(), argv
[0], argv
[1], &s
))
419 xprintf("%s\n", nullcheck(utf82mb(s
)));
422 static int isarg_option(const char *arg
) {
423 return arg
[0] == '-';
426 static int argvlen(char **argv
) {
434 static const struct option setup_guest_options
[] = {
435 { "help", no_argument
, 0, 'h' },
436 { "online-registration", no_argument
, 0, 'r' },
437 { "no-online-registration", no_argument
, 0, 'R' },
441 static void help_setup_guest(void) {
443 " disorder setup-guest [OPTIONS]\n"
445 " --help, -h Display usage message\n"
446 " --online-registration Enable online registration (default)\n"
447 " --no-online-registration Disable online registration\n");
452 static void cf_setup_guest(char **argv
) {
453 int n
, online_registration
= 1;
455 while((n
= getopt_long(argvlen(argv
) + 1, argv
- 1,
456 "hrR", setup_guest_options
, 0)) >= 0) {
458 case 'h': help_setup_guest();
459 case 'r': online_registration
= 1; break;
460 case 'R': online_registration
= 0; break;
461 default: fatal(0, "invalid option");
464 if(online_registration
&& !config
->mail_sender
)
465 fatal(0, "you MUST set mail_sender if you want online registration");
466 if(disorder_adduser(getclient(), "guest", "",
467 online_registration ?
"read,register" : "read"))
471 struct scheduled_event
{
473 struct kvp
*actiondata
;
477 static int compare_event(const void *av
, const void *bv
) {
478 struct scheduled_event
*a
= (void *)av
, *b
= (void *)bv
;
480 /* Primary sort key is the trigger time */
481 if(a
->when
< b
->when
)
483 else if(a
->when
> b
->when
)
485 /* For events that go off at the same time just sort by ID */
486 return strcmp(a
->id
, b
->id
);
489 static void cf_schedule_list(char attribute((unused
)) **argv
) {
492 struct scheduled_event
*events
;
494 const char *action
, *key
, *value
, *priority
;
497 /* Get all known events */
498 if(disorder_schedule_list(getclient(), &ids
, &nids
))
500 events
= xcalloc(nids
, sizeof *events
);
501 for(n
= 0; n
< nids
; ++n
) {
502 events
[n
].id
= ids
[n
];
503 if(disorder_schedule_get(getclient(), ids
[n
], &events
[n
].actiondata
))
505 events
[n
].when
= atoll(kvp_get(events
[n
].actiondata
, "when"));
507 /* Sort by trigger time */
508 qsort(events
, nids
, sizeof *events
, compare_event
);
510 for(n
= 0; n
< nids
; ++n
) {
511 strftime(tb
, sizeof tb
, "%Y-%m-%d %H:%M:%S %Z", localtime(&events
[n
].when
));
512 action
= kvp_get(events
[n
].actiondata
, "action");
513 priority
= kvp_get(events
[n
].actiondata
, "priority");
514 if(!strcmp(priority
, "junk"))
516 else if(!strcmp(priority
, "normal"))
520 xprintf("%11s %-25s %c %-8s %s",
521 events
[n
].id
, tb
, prichar
, kvp_get(events
[n
].actiondata
, "who"),
523 if(!strcmp(action
, "play"))
525 nullcheck(utf82mb(kvp_get(events
[n
].actiondata
, "track"))));
526 else if(!strcmp(action
, "set-global")) {
527 key
= kvp_get(events
[n
].actiondata
, "key");
528 value
= kvp_get(events
[n
].actiondata
, "value");
531 nullcheck(utf82mb(key
)),
532 nullcheck(utf82mb(value
)));
535 nullcheck(utf82mb(key
)));
541 static void cf_schedule_del(char **argv
) {
542 if(disorder_schedule_del(getclient(), argv
[0]))
546 static void cf_schedule_play(char **argv
) {
547 if(disorder_schedule_add(getclient(),
555 static void cf_schedule_set_global(char **argv
) {
556 if(disorder_schedule_add(getclient(),
565 static void cf_schedule_unset_global(char **argv
) {
566 if(disorder_schedule_add(getclient(),
575 static const struct command
{
579 int (*isarg
)(const char *);
580 const char *argstr
, *desc
;
582 { "adduser", 2, 3, cf_adduser
, isarg_rights
, "USERNAME PASSWORD [RIGHTS]",
583 "Create a new user" },
584 { "allfiles", 1, 2, cf_allfiles
, isarg_regexp
, "DIR [~REGEXP]",
585 "List all files and directories in DIR" },
586 { "authorize", 1, 2, cf_authorize
, isarg_rights
, "USERNAME [RIGHTS]",
587 "Authorize user USERNAME to connect" },
588 { "deluser", 1, 1, cf_deluser
, 0, "USERNAME",
589 "Delete user USERNAME" },
590 { "dirs", 1, 2, cf_dirs
, isarg_regexp
, "DIR [~REGEXP]",
591 "List directories in DIR" },
592 { "disable", 0, 0, cf_disable
, 0, "",
594 { "disable-random", 0, 0, cf_random_disable
, 0, "",
595 "Disable random play" },
596 { "edituser", 3, 3, cf_edituser
, 0, "USERNAME PROPERTY VALUE",
597 "Set a property of user USERNAME" },
598 { "enable", 0, 0, cf_enable
, 0, "",
600 { "enable-random", 0, 0, cf_random_enable
, 0, "",
601 "Enable random play" },
602 { "files", 1, 2, cf_files
, isarg_regexp
, "DIR [~REGEXP]",
603 "List files in DIR" },
604 { "get", 2, 2, cf_get
, 0, "TRACK NAME",
605 "Get a preference value" },
606 { "get-global", 1, 1, cf_get_global
, 0, "NAME",
607 "Get a global preference value" },
608 { "get-volume", 0, 0, cf_get_volume
, 0, "",
609 "Get the current volume" },
610 { "length", 1, 1, cf_length
, 0, "TRACK",
611 "Get the length of TRACK in seconds" },
612 { "log", 0, 0, cf_log
, 0, "",
613 "Copy event log to stdout" },
614 { "move", 2, 2, cf_move
, 0, "TRACK DELTA",
615 "Move a track in the queue" },
616 { "new", 0, 1, cf_new
, isarg_integer
, "[MAX]",
617 "Get the most recently added MAX tracks" },
618 { "part", 3, 3, cf_part
, 0, "TRACK CONTEXT PART",
619 "Find a track name part" },
620 { "pause", 0, 0, cf_pause
, 0, "",
621 "Pause the currently playing track" },
622 { "play", 1, INT_MAX
, cf_play
, isarg_filename
, "TRACKS...",
623 "Add TRACKS to the end of the queue" },
624 { "playing", 0, 0, cf_playing
, 0, "",
625 "Report the playing track" },
626 { "prefs", 1, 1, cf_prefs
, 0, "TRACK",
627 "Display all the preferences for TRACK" },
628 { "quack", 0, 0, cf_quack
, 0, 0, 0 },
629 { "queue", 0, 0, cf_queue
, 0, "",
630 "Display the current queue" },
631 { "random-disable", 0, 0, cf_random_disable
, 0, "",
632 "Disable random play" },
633 { "random-enable", 0, 0, cf_random_enable
, 0, "",
634 "Enable random play" },
635 { "recent", 0, 0, cf_recent
, 0, "",
636 "Display recently played track" },
637 { "reconfigure", 0, 0, cf_reconfigure
, 0, "",
638 "Reconfigure the daemon" },
639 { "remove", 1, 1, cf_remove
, 0, "TRACK",
640 "Remove a track from the queue" },
641 { "rescan", 0, 0, cf_rescan
, 0, "",
642 "Rescan for new tracks" },
643 { "resolve", 1, 1, cf_resolve
, 0, "TRACK",
644 "Resolve alias for TRACK" },
645 { "resume", 0, 0, cf_resume
, 0, "",
646 "Resume after a pause" },
647 { "rtp-address", 0, 0, cf_rtp_address
, 0, "",
648 "Report server's broadcast address" },
649 { "schedule-del", 1, 1, cf_schedule_del
, 0, "EVENT",
650 "Delete a scheduled event" },
651 { "schedule-list", 0, 0, cf_schedule_list
, 0, "",
652 "List scheduled events" },
653 { "schedule-play", 3, 3, cf_schedule_play
, 0, "WHEN PRI TRACK",
654 "Play TRACK later" },
655 { "schedule-set-global", 4, 4, cf_schedule_set_global
, 0, "WHEN PRI NAME VAL",
656 "Set a global preference later" },
657 { "schedule-unset-global", 3, 3, cf_schedule_unset_global
, 0, "WHEN PRI NAME",
658 "Unset a global preference later" },
659 { "scratch", 0, 0, cf_scratch
, 0, "",
660 "Scratch the currently playing track" },
661 { "scratch-id", 1, 1, cf_scratch
, 0, "ID",
662 "Scratch the currently playing track" },
663 { "search", 1, 1, cf_search
, 0, "WORDS",
664 "Display tracks matching all the words" },
665 { "set", 3, 3, cf_set
, 0, "TRACK NAME VALUE",
666 "Set a preference value" },
667 { "set-global", 2, 2, cf_set_global
, 0, "NAME VALUE",
668 "Set a global preference value" },
669 { "set-volume", 2, 2, cf_set_volume
, 0, "LEFT RIGHT",
671 { "setup-guest", 0, INT_MAX
, cf_setup_guest
, isarg_option
, "[OPTIONS]",
672 "Create the guest login" },
673 { "shutdown", 0, 0, cf_shutdown
, 0, "",
674 "Shut down the daemon" },
675 { "stats", 0, 0, cf_stats
, 0, "",
676 "Display server statistics" },
677 { "tags", 0, 0, cf_tags
, 0, "",
679 { "unset", 2, 2, cf_unset
, 0, "TRACK NAME",
680 "Unset a preference" },
681 { "unset-global", 1, 1, cf_unset_global
, 0, "NAME",
682 "Unset a global preference" },
683 { "userinfo", 2, 2, cf_userinfo
, 0, "USERNAME PROPERTY",
684 "Get a property of a user" },
685 { "users", 0, 0, cf_users
, 0, "",
687 { "version", 0, 0, cf_version
, 0, "",
688 "Display the server version" },
691 static void help_commands(void) {
692 unsigned n
, max
= 0, l
;
694 xprintf("Command summary:\n");
695 for(n
= 0; n
< sizeof commands
/ sizeof *commands
; ++n
) {
696 if(!commands
[n
].desc
) continue;
697 l
= strlen(commands
[n
].name
);
698 if(*commands
[n
].argstr
)
699 l
+= strlen(commands
[n
].argstr
) + 1;
703 for(n
= 0; n
< sizeof commands
/ sizeof *commands
; ++n
) {
704 if(!commands
[n
].desc
) continue;
705 l
= strlen(commands
[n
].name
);
706 if(*commands
[n
].argstr
)
707 l
+= strlen(commands
[n
].argstr
) + 1;
708 xprintf(" %s%s%s%*s %s\n", commands
[n
].name
,
709 *commands
[n
].argstr ?
" " : "",
718 int main(int argc
, char **argv
) {
719 int n
, i
, j
, local
= 0;
722 const char *user
= 0, *password
= 0;
725 /* garbage-collect PCRE's memory */
726 pcre_malloc
= xmalloc
;
728 if(!setlocale(LC_CTYPE
, "")) fatal(errno
, "error calling setlocale");
729 while((n
= getopt_long(argc
, argv
, "+hVc:dHlNu:p:", options
, 0)) >= 0) {
732 case 'H': help_commands();
733 case 'V': version("disorder");
734 case 'c': configfile
= optarg
; break;
735 case 'd': debugging
= 1; break;
736 case 'l': local
= 1; break;
737 case 'N': config_per_user
= 0; break;
738 case 'u': user
= optarg
; break;
739 case 'p': password
= optarg
; break;
740 default: fatal(0, "invalid option");
743 if(config_read(0)) fatal(0, "cannot read configuration");
745 config
->username
= user
;
746 config
->password
= 0;
749 config
->password
= password
;
751 config
->connect
.n
= 0;
753 optind
= 1; /* for subsequent getopt calls */
754 /* accumulate command args */
756 if((i
= TABLE_FIND(commands
, struct command
, name
, argv
[n
])) < 0)
757 fatal(0, "unknown command '%s'", argv
[n
]);
758 if(n
+ commands
[i
].min
>= argc
)
759 fatal(0, "missing arguments to '%s'", argv
[n
]);
761 /* Include the command name in the args, but at element -1, for
762 * the benefit of subcommand getopt calls */
763 vector_append(&args
, argv
[n
]);
765 for(j
= 0; j
< commands
[i
].min
; ++j
)
766 vector_append(&args
, nullcheck(mb2utf8(argv
[n
+ j
])));
767 for(; j
< commands
[i
].max
769 && commands
[i
].isarg(argv
[n
+ j
]); ++j
)
770 vector_append(&args
, nullcheck(mb2utf8(argv
[n
+ j
])));
771 vector_terminate(&args
);
772 commands
[i
].fn(args
.vec
+ 1);
775 if(client
&& disorder_close(client
)) exit(EXIT_FAILURE
);
776 if(fclose(stdout
) < 0) fatal(errno
, "error closing stdout");