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
24 #include <sys/types.h>
25 #include <sys/socket.h>
35 #include "configuration.h"
48 #include "authorize.h"
51 #include "dateparse.h"
53 static disorder_client
*client
;
55 static const struct option options
[] = {
56 { "help", no_argument
, 0, 'h' },
57 { "version", no_argument
, 0, 'V' },
58 { "config", required_argument
, 0, 'c' },
59 { "debug", no_argument
, 0, 'd' },
60 { "local", no_argument
, 0, 'l' },
61 { "no-per-user-config", no_argument
, 0, 'N' },
62 { "help-commands", no_argument
, 0, 'H' },
63 { "user", required_argument
, 0, 'u' },
64 { "password", required_argument
, 0, 'p' },
68 /* display usage message and terminate */
69 static void help(void) {
71 " disorder [OPTIONS] COMMAND ...\n"
73 " --help, -h Display usage message\n"
74 " --help-commands, -H List commands\n"
75 " --version, -V Display version number\n"
76 " --config PATH, -c PATH Set configuration file\n"
77 " --local, -l Force connection to local server\n"
78 " --debug, -d Turn on debugging\n");
83 static disorder_client
*getclient(void) {
85 if(!(client
= disorder_new(1))) exit(EXIT_FAILURE
);
86 if(disorder_connect(client
)) exit(EXIT_FAILURE
);
91 static void cf_version(char attribute((unused
)) **argv
) {
94 if(disorder_version(getclient(), &v
)) exit(EXIT_FAILURE
);
95 xprintf("%s\n", nullcheck(utf82mb(v
)));
98 static void print_queue_entry(const struct queue_entry
*q
) {
99 if(q
->track
) xprintf("track %s\n", nullcheck(utf82mb(q
->track
)));
100 if(q
->id
) xprintf(" id %s\n", nullcheck(utf82mb(q
->id
)));
101 if(q
->submitter
) xprintf(" submitted by %s at %s",
102 nullcheck(utf82mb(q
->submitter
)), ctime(&q
->when
));
103 if(q
->played
) xprintf(" played at %s", ctime(&q
->played
));
104 if(q
->state
== playing_started
105 || q
->state
== playing_paused
) xprintf(" %lds so far", q
->sofar
);
106 else if(q
->expected
) xprintf(" might start at %s", ctime(&q
->expected
));
107 if(q
->scratched
) xprintf(" scratched by %s\n",
108 nullcheck(utf82mb(q
->scratched
)));
109 else xprintf(" %s\n", playing_states
[q
->state
]);
110 if(q
->wstat
) xprintf(" %s\n", wstat(q
->wstat
));
113 static void cf_playing(char attribute((unused
)) **argv
) {
114 struct queue_entry
*q
;
116 if(disorder_playing(getclient(), &q
)) exit(EXIT_FAILURE
);
118 print_queue_entry(q
);
120 xprintf("nothing\n");
123 static void cf_play(char **argv
) {
125 if(disorder_play(getclient(), *argv
++)) exit(EXIT_FAILURE
);
128 static void cf_remove(char **argv
) {
129 if(disorder_remove(getclient(), argv
[0])) exit(EXIT_FAILURE
);
132 static void cf_disable(char attribute((unused
)) **argv
) {
133 if(disorder_disable(getclient())) exit(EXIT_FAILURE
);
136 static void cf_enable(char attribute((unused
)) **argv
) {
137 if(disorder_enable(getclient())) exit(EXIT_FAILURE
);
140 static void cf_scratch(char **argv
) {
141 if(disorder_scratch(getclient(), argv
[0])) exit(EXIT_FAILURE
);
144 static void cf_shutdown(char attribute((unused
)) **argv
) {
145 if(disorder_shutdown(getclient())) exit(EXIT_FAILURE
);
148 static void cf_reconfigure(char attribute((unused
)) **argv
) {
149 /* Re-check configuration for server */
150 if(config_read(1)) fatal(0, "cannot read configuration");
151 if(disorder_reconfigure(getclient())) exit(EXIT_FAILURE
);
154 static void cf_rescan(char attribute((unused
)) **argv
) {
155 if(disorder_rescan(getclient())) exit(EXIT_FAILURE
);
158 static void cf_somequeue(int (*fn
)(disorder_client
*c
,
159 struct queue_entry
**qp
)) {
160 struct queue_entry
*q
;
162 if(fn(getclient(), &q
)) exit(EXIT_FAILURE
);
164 print_queue_entry(q
);
169 static void cf_recent(char attribute((unused
)) **argv
) {
170 cf_somequeue(disorder_recent
);
173 static void cf_queue(char attribute((unused
)) **argv
) {
174 cf_somequeue(disorder_queue
);
177 static void cf_quack(char attribute((unused
)) **argv
) {
179 " .------------------.\n"
180 " | Naath is a babe! |\n"
181 " `---------+--------'\n"
185 "~~~~~~~~~~~~~~~~~~~~~~\n"
189 static void cf_somelist(char **argv
,
190 int (*fn
)(disorder_client
*c
,
191 const char *arg
, const char *re
,
192 char ***vecp
, int *nvecp
)) {
197 re
= xstrdup(argv
[1] + 1);
200 if(fn(getclient(), argv
[0], re
, &vec
, 0)) exit(EXIT_FAILURE
);
202 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
205 static int isarg_regexp(const char *s
) {
209 static void cf_dirs(char **argv
) {
210 cf_somelist(argv
, disorder_directories
);
213 static void cf_files(char **argv
) {
214 cf_somelist(argv
, disorder_files
);
217 static void cf_allfiles(char **argv
) {
218 cf_somelist(argv
, disorder_allfiles
);
221 static void cf_get(char **argv
) {
224 if(disorder_get(getclient(), argv
[0], argv
[1], &value
)) exit(EXIT_FAILURE
);
225 xprintf("%s\n", nullcheck(utf82mb(value
)));
228 static void cf_length(char **argv
) {
231 if(disorder_length(getclient(), argv
[0], &length
)) exit(EXIT_FAILURE
);
232 xprintf("%ld\n", length
);
235 static void cf_set(char **argv
) {
236 if(disorder_set(getclient(), argv
[0], argv
[1], argv
[2])) exit(EXIT_FAILURE
);
239 static void cf_unset(char **argv
) {
240 if(disorder_unset(getclient(), argv
[0], argv
[1])) exit(EXIT_FAILURE
);
243 static void cf_prefs(char **argv
) {
246 if(disorder_prefs(getclient(), argv
[0], &k
)) exit(EXIT_FAILURE
);
247 for(; k
; k
= k
->next
)
249 nullcheck(utf82mb(k
->name
)), nullcheck(utf82mb(k
->value
)));
252 static void cf_search(char **argv
) {
256 if(disorder_search(getclient(), *argv
, &results
, &nresults
)) exit(EXIT_FAILURE
);
257 for(n
= 0; n
< nresults
; ++n
)
258 xprintf("%s\n", nullcheck(utf82mb(results
[n
])));
261 static void cf_random_disable(char attribute((unused
)) **argv
) {
262 if(disorder_random_disable(getclient())) exit(EXIT_FAILURE
);
265 static void cf_random_enable(char attribute((unused
)) **argv
) {
266 if(disorder_random_enable(getclient())) exit(EXIT_FAILURE
);
269 static void cf_stats(char attribute((unused
)) **argv
) {
272 if(disorder_stats(getclient(), &vec
, 0)) exit(EXIT_FAILURE
);
274 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
277 static void cf_get_volume(char attribute((unused
)) **argv
) {
280 if(disorder_get_volume(getclient(), &l
, &r
)) exit(EXIT_FAILURE
);
281 xprintf("%d %d\n", l
, r
);
284 static void cf_set_volume(char **argv
) {
285 if(disorder_set_volume(getclient(), atoi(argv
[0]), atoi(argv
[1]))) exit(EXIT_FAILURE
);
288 static void cf_log(char attribute((unused
)) **argv
) {
289 if(disorder_log(getclient(), sink_stdio("stdout", stdout
))) exit(EXIT_FAILURE
);
292 static void cf_move(char **argv
) {
296 if((e
= xstrtol(&n
, argv
[1], 0, 10)))
297 fatal(e
, "cannot convert '%s'", argv
[1]);
298 if(n
> INT_MAX
|| n
< INT_MIN
)
299 fatal(e
, "%ld out of range", n
);
300 if(disorder_move(getclient(), argv
[0], (int)n
)) exit(EXIT_FAILURE
);
303 static void cf_part(char **argv
) {
306 if(disorder_part(getclient(), &s
, argv
[0], argv
[1], argv
[2])) exit(EXIT_FAILURE
);
307 xprintf("%s\n", nullcheck(utf82mb(s
)));
310 static int isarg_filename(const char *s
) {
314 static void cf_authorize(char **argv
) {
315 authorize(getclient(), argv
[0], argv
[1]);
318 static void cf_resolve(char **argv
) {
321 if(disorder_resolve(getclient(), &track
, argv
[0])) exit(EXIT_FAILURE
);
322 xprintf("%s\n", nullcheck(utf82mb(track
)));
325 static void cf_pause(char attribute((unused
)) **argv
) {
326 if(disorder_pause(getclient())) exit(EXIT_FAILURE
);
329 static void cf_resume(char attribute((unused
)) **argv
) {
330 if(disorder_resume(getclient())) exit(EXIT_FAILURE
);
333 static void cf_tags(char attribute((unused
)) **argv
) {
336 if(disorder_tags(getclient(), &vec
, 0)) exit(EXIT_FAILURE
);
338 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
341 static void cf_users(char attribute((unused
)) **argv
) {
344 if(disorder_users(getclient(), &vec
, 0)) exit(EXIT_FAILURE
);
346 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
349 static void cf_get_global(char **argv
) {
352 if(disorder_get_global(getclient(), argv
[0], &value
)) exit(EXIT_FAILURE
);
353 xprintf("%s\n", nullcheck(utf82mb(value
)));
356 static void cf_set_global(char **argv
) {
357 if(disorder_set_global(getclient(), argv
[0], argv
[1])) exit(EXIT_FAILURE
);
360 static void cf_unset_global(char **argv
) {
361 if(disorder_unset_global(getclient(), argv
[0])) exit(EXIT_FAILURE
);
364 static int isarg_integer(const char *s
) {
367 if(!isdigit((unsigned char)*s
))
374 static void cf_new(char **argv
) {
377 if(disorder_new_tracks(getclient(), &vec
, 0, argv
[0] ?
atoi(argv
[0]) : 0))
380 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
383 static void cf_rtp_address(char attribute((unused
)) **argv
) {
384 char *address
, *port
;
386 if(disorder_rtp_address(getclient(), &address
, &port
)) exit(EXIT_FAILURE
);
387 xprintf("address: %s\nport: %s\n", address
, port
);
390 static int isarg_rights(const char *arg
) {
391 return strchr(arg
, ',') || !parse_rights(arg
, 0, 0);
394 static void cf_adduser(char **argv
) {
395 if(disorder_adduser(getclient(), argv
[0], argv
[1], argv
[2]))
399 static void cf_deluser(char **argv
) {
400 if(disorder_deluser(getclient(), argv
[0]))
404 static void cf_edituser(char **argv
) {
405 if(disorder_edituser(getclient(), argv
[0], argv
[1], argv
[2]))
409 static void cf_userinfo(char **argv
) {
412 if(disorder_userinfo(getclient(), argv
[0], argv
[1], &s
))
414 xprintf("%s\n", nullcheck(utf82mb(s
)));
417 static int isarg_option(const char *arg
) {
418 return arg
[0] == '-';
421 static int argvlen(char **argv
) {
429 static const struct option setup_guest_options
[] = {
430 { "help", no_argument
, 0, 'h' },
431 { "online-registration", no_argument
, 0, 'r' },
432 { "no-online-registration", no_argument
, 0, 'R' },
436 static void help_setup_guest(void) {
438 " disorder setup-guest [OPTIONS]\n"
440 " --help, -h Display usage message\n"
441 " --online-registration Enable online registration (default)\n"
442 " --no-online-registration Disable online registration\n");
447 static void cf_setup_guest(char **argv
) {
448 int n
, online_registration
= 1;
450 while((n
= getopt_long(argvlen(argv
) + 1, argv
- 1,
451 "hrR", setup_guest_options
, 0)) >= 0) {
453 case 'h': help_setup_guest();
454 case 'r': online_registration
= 1; break;
455 case 'R': online_registration
= 0; break;
456 default: fatal(0, "invalid option");
459 if(online_registration
&& !config
->mail_sender
)
460 fatal(0, "you MUST set mail_sender if you want online registration");
461 if(disorder_adduser(getclient(), "guest", "",
462 online_registration ?
"read,register" : "read"))
466 struct scheduled_event
{
468 struct kvp
*actiondata
;
472 static int compare_event(const void *av
, const void *bv
) {
473 struct scheduled_event
*a
= (void *)av
, *b
= (void *)bv
;
475 /* Primary sort key is the trigger time */
476 if(a
->when
< b
->when
)
478 else if(a
->when
> b
->when
)
480 /* For events that go off at the same time just sort by ID */
481 return strcmp(a
->id
, b
->id
);
484 static void cf_schedule_list(char attribute((unused
)) **argv
) {
487 struct scheduled_event
*events
;
489 const char *action
, *key
, *value
, *priority
;
492 /* Get all known events */
493 if(disorder_schedule_list(getclient(), &ids
, &nids
))
495 events
= xcalloc(nids
, sizeof *events
);
496 for(n
= 0; n
< nids
; ++n
) {
497 events
[n
].id
= ids
[n
];
498 if(disorder_schedule_get(getclient(), ids
[n
], &events
[n
].actiondata
))
500 events
[n
].when
= atoll(kvp_get(events
[n
].actiondata
, "when"));
502 /* Sort by trigger time */
503 qsort(events
, nids
, sizeof *events
, compare_event
);
505 for(n
= 0; n
< nids
; ++n
) {
506 strftime(tb
, sizeof tb
, "%Y-%m-%d %H:%M:%S %Z", localtime(&events
[n
].when
));
507 action
= kvp_get(events
[n
].actiondata
, "action");
508 priority
= kvp_get(events
[n
].actiondata
, "priority");
509 if(!strcmp(priority
, "junk"))
511 else if(!strcmp(priority
, "normal"))
515 xprintf("%11s %-25s %c %-8s %s",
516 events
[n
].id
, tb
, prichar
, kvp_get(events
[n
].actiondata
, "who"),
518 if(!strcmp(action
, "play"))
520 nullcheck(utf82mb(kvp_get(events
[n
].actiondata
, "track"))));
521 else if(!strcmp(action
, "set-global")) {
522 key
= kvp_get(events
[n
].actiondata
, "key");
523 value
= kvp_get(events
[n
].actiondata
, "value");
526 nullcheck(utf82mb(key
)),
527 nullcheck(utf82mb(value
)));
530 nullcheck(utf82mb(key
)));
536 static void cf_schedule_del(char **argv
) {
537 if(disorder_schedule_del(getclient(), argv
[0]))
541 static void cf_schedule_play(char **argv
) {
542 if(disorder_schedule_add(getclient(),
550 static void cf_schedule_set_global(char **argv
) {
551 if(disorder_schedule_add(getclient(),
560 static void cf_schedule_unset_global(char **argv
) {
561 if(disorder_schedule_add(getclient(),
570 static const struct command
{
574 int (*isarg
)(const char *);
575 const char *argstr
, *desc
;
577 { "adduser", 2, 3, cf_adduser
, isarg_rights
, "USERNAME PASSWORD [RIGHTS]",
578 "Create a new user" },
579 { "allfiles", 1, 2, cf_allfiles
, isarg_regexp
, "DIR [~REGEXP]",
580 "List all files and directories in DIR" },
581 { "authorize", 1, 2, cf_authorize
, isarg_rights
, "USERNAME [RIGHTS]",
582 "Authorize user USERNAME to connect" },
583 { "deluser", 1, 1, cf_deluser
, 0, "USERNAME",
584 "Delete user USERNAME" },
585 { "dirs", 1, 2, cf_dirs
, isarg_regexp
, "DIR [~REGEXP]",
586 "List directories in DIR" },
587 { "disable", 0, 0, cf_disable
, 0, "",
589 { "disable-random", 0, 0, cf_random_disable
, 0, "",
590 "Disable random play" },
591 { "edituser", 3, 3, cf_edituser
, 0, "USERNAME PROPERTY VALUE",
592 "Set a property of user USERNAME" },
593 { "enable", 0, 0, cf_enable
, 0, "",
595 { "enable-random", 0, 0, cf_random_enable
, 0, "",
596 "Enable random play" },
597 { "files", 1, 2, cf_files
, isarg_regexp
, "DIR [~REGEXP]",
598 "List files in DIR" },
599 { "get", 2, 2, cf_get
, 0, "TRACK NAME",
600 "Get a preference value" },
601 { "get-global", 1, 1, cf_get_global
, 0, "NAME",
602 "Get a global preference value" },
603 { "get-volume", 0, 0, cf_get_volume
, 0, "",
604 "Get the current volume" },
605 { "length", 1, 1, cf_length
, 0, "TRACK",
606 "Get the length of TRACK in seconds" },
607 { "log", 0, 0, cf_log
, 0, "",
608 "Copy event log to stdout" },
609 { "move", 2, 2, cf_move
, 0, "TRACK DELTA",
610 "Move a track in the queue" },
611 { "new", 0, 1, cf_new
, isarg_integer
, "[MAX]",
612 "Get the most recently added MAX tracks" },
613 { "part", 3, 3, cf_part
, 0, "TRACK CONTEXT PART",
614 "Find a track name part" },
615 { "pause", 0, 0, cf_pause
, 0, "",
616 "Pause the currently playing track" },
617 { "play", 1, INT_MAX
, cf_play
, isarg_filename
, "TRACKS...",
618 "Add TRACKS to the end of the queue" },
619 { "playing", 0, 0, cf_playing
, 0, "",
620 "Report the playing track" },
621 { "prefs", 1, 1, cf_prefs
, 0, "TRACK",
622 "Display all the preferences for TRACK" },
623 { "quack", 0, 0, cf_quack
, 0, 0, 0 },
624 { "queue", 0, 0, cf_queue
, 0, "",
625 "Display the current queue" },
626 { "random-disable", 0, 0, cf_random_disable
, 0, "",
627 "Disable random play" },
628 { "random-enable", 0, 0, cf_random_enable
, 0, "",
629 "Enable random play" },
630 { "recent", 0, 0, cf_recent
, 0, "",
631 "Display recently played track" },
632 { "reconfigure", 0, 0, cf_reconfigure
, 0, "",
633 "Reconfigure the daemon" },
634 { "remove", 1, 1, cf_remove
, 0, "TRACK",
635 "Remove a track from the queue" },
636 { "rescan", 0, 0, cf_rescan
, 0, "",
637 "Rescan for new tracks" },
638 { "resolve", 1, 1, cf_resolve
, 0, "TRACK",
639 "Resolve alias for TRACK" },
640 { "resume", 0, 0, cf_resume
, 0, "",
641 "Resume after a pause" },
642 { "rtp-address", 0, 0, cf_rtp_address
, 0, "",
643 "Report server's broadcast address" },
644 { "schedule-del", 1, 1, cf_schedule_del
, 0, "EVENT",
645 "Delete a scheduled event" },
646 { "schedule-list", 0, 0, cf_schedule_list
, 0, "",
647 "List scheduled events" },
648 { "schedule-play", 3, 3, cf_schedule_play
, 0, "WHEN PRI TRACK",
649 "Play TRACK later" },
650 { "schedule-set-global", 4, 4, cf_schedule_set_global
, 0, "WHEN PRI NAME VAL",
651 "Set a global preference later" },
652 { "schedule-unset-global", 3, 3, cf_schedule_unset_global
, 0, "WHEN PRI NAME",
653 "Unset a global preference later" },
654 { "scratch", 0, 0, cf_scratch
, 0, "",
655 "Scratch the currently playing track" },
656 { "scratch-id", 1, 1, cf_scratch
, 0, "ID",
657 "Scratch the currently playing track" },
658 { "search", 1, 1, cf_search
, 0, "WORDS",
659 "Display tracks matching all the words" },
660 { "set", 3, 3, cf_set
, 0, "TRACK NAME VALUE",
661 "Set a preference value" },
662 { "set-global", 2, 2, cf_set_global
, 0, "NAME VALUE",
663 "Set a global preference value" },
664 { "set-volume", 2, 2, cf_set_volume
, 0, "LEFT RIGHT",
666 { "setup-guest", 0, INT_MAX
, cf_setup_guest
, isarg_option
, "[OPTIONS]",
667 "Create the guest login" },
668 { "shutdown", 0, 0, cf_shutdown
, 0, "",
669 "Shut down the daemon" },
670 { "stats", 0, 0, cf_stats
, 0, "",
671 "Display server statistics" },
672 { "tags", 0, 0, cf_tags
, 0, "",
674 { "unset", 2, 2, cf_unset
, 0, "TRACK NAME",
675 "Unset a preference" },
676 { "unset-global", 1, 1, cf_unset_global
, 0, "NAME",
677 "Unset a global preference" },
678 { "userinfo", 2, 2, cf_userinfo
, 0, "USERNAME PROPERTY",
679 "Get a property of a user" },
680 { "users", 0, 0, cf_users
, 0, "",
682 { "version", 0, 0, cf_version
, 0, "",
683 "Display the server version" },
686 static void help_commands(void) {
687 unsigned n
, max
= 0, l
;
689 xprintf("Command summary:\n");
690 for(n
= 0; n
< sizeof commands
/ sizeof *commands
; ++n
) {
691 if(!commands
[n
].desc
) continue;
692 l
= strlen(commands
[n
].name
);
693 if(*commands
[n
].argstr
)
694 l
+= strlen(commands
[n
].argstr
) + 1;
698 for(n
= 0; n
< sizeof commands
/ sizeof *commands
; ++n
) {
699 if(!commands
[n
].desc
) continue;
700 l
= strlen(commands
[n
].name
);
701 if(*commands
[n
].argstr
)
702 l
+= strlen(commands
[n
].argstr
) + 1;
703 xprintf(" %s%s%s%*s %s\n", commands
[n
].name
,
704 *commands
[n
].argstr ?
" " : "",
713 int main(int argc
, char **argv
) {
714 int n
, i
, j
, local
= 0;
717 const char *user
= 0, *password
= 0;
720 /* garbage-collect PCRE's memory */
721 pcre_malloc
= xmalloc
;
723 if(!setlocale(LC_CTYPE
, "")) fatal(errno
, "error calling setlocale");
724 if(!setlocale(LC_TIME
, "")) fatal(errno
, "error calling setlocale");
725 while((n
= getopt_long(argc
, argv
, "+hVc:dHlNu:p:", options
, 0)) >= 0) {
728 case 'H': help_commands();
729 case 'V': version("disorder");
730 case 'c': configfile
= optarg
; break;
731 case 'd': debugging
= 1; break;
732 case 'l': local
= 1; break;
733 case 'N': config_per_user
= 0; break;
734 case 'u': user
= optarg
; break;
735 case 'p': password
= optarg
; break;
736 default: fatal(0, "invalid option");
739 if(config_read(0)) fatal(0, "cannot read configuration");
741 config
->username
= user
;
742 config
->password
= 0;
745 config
->password
= password
;
747 config
->connect
.n
= 0;
749 optind
= 1; /* for subsequent getopt calls */
750 /* accumulate command args */
752 if((i
= TABLE_FIND(commands
, name
, argv
[n
])) < 0)
753 fatal(0, "unknown command '%s'", argv
[n
]);
754 if(n
+ commands
[i
].min
>= argc
)
755 fatal(0, "missing arguments to '%s'", argv
[n
]);
757 /* Include the command name in the args, but at element -1, for
758 * the benefit of subcommand getopt calls */
759 vector_append(&args
, argv
[n
]);
761 for(j
= 0; j
< commands
[i
].min
; ++j
)
762 vector_append(&args
, nullcheck(mb2utf8(argv
[n
+ j
])));
763 for(; j
< commands
[i
].max
765 && commands
[i
].isarg(argv
[n
+ j
]); ++j
)
766 vector_append(&args
, nullcheck(mb2utf8(argv
[n
+ j
])));
767 vector_terminate(&args
);
768 commands
[i
].fn(args
.vec
+ 1);
771 if(client
&& disorder_close(client
)) exit(EXIT_FAILURE
);
772 if(fclose(stdout
) < 0) fatal(errno
, "error closing stdout");