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
)));
105 case origin_scheduled
:
106 xprintf(" %s by %s at %s",
107 track_origins
[q
->origin
],
108 nullcheck(utf82mb(q
->submitter
)), ctime(&q
->when
));
113 if(q
->played
) xprintf(" played at %s", ctime(&q
->played
));
114 if(q
->state
== playing_started
115 || q
->state
== playing_paused
) xprintf(" %lds so far", q
->sofar
);
116 else if(q
->expected
) xprintf(" might start at %s", ctime(&q
->expected
));
117 if(q
->scratched
) xprintf(" scratched by %s\n",
118 nullcheck(utf82mb(q
->scratched
)));
119 else xprintf(" %s\n", playing_states
[q
->state
]);
120 if(q
->wstat
) xprintf(" %s\n", wstat(q
->wstat
));
123 static void cf_playing(char attribute((unused
)) **argv
) {
124 struct queue_entry
*q
;
126 if(disorder_playing(getclient(), &q
)) exit(EXIT_FAILURE
);
128 print_queue_entry(q
);
130 xprintf("nothing\n");
133 static void cf_play(char **argv
) {
135 if(disorder_play(getclient(), *argv
++)) exit(EXIT_FAILURE
);
138 static void cf_remove(char **argv
) {
139 if(disorder_remove(getclient(), argv
[0])) exit(EXIT_FAILURE
);
142 static void cf_disable(char attribute((unused
)) **argv
) {
143 if(disorder_disable(getclient())) exit(EXIT_FAILURE
);
146 static void cf_enable(char attribute((unused
)) **argv
) {
147 if(disorder_enable(getclient())) exit(EXIT_FAILURE
);
150 static void cf_scratch(char **argv
) {
151 if(disorder_scratch(getclient(), argv
[0])) exit(EXIT_FAILURE
);
154 static void cf_shutdown(char attribute((unused
)) **argv
) {
155 if(disorder_shutdown(getclient())) exit(EXIT_FAILURE
);
158 static void cf_reconfigure(char attribute((unused
)) **argv
) {
159 /* Re-check configuration for server */
160 if(config_read(1)) fatal(0, "cannot read configuration");
161 if(disorder_reconfigure(getclient())) exit(EXIT_FAILURE
);
164 static void cf_rescan(char attribute((unused
)) **argv
) {
165 if(disorder_rescan(getclient())) exit(EXIT_FAILURE
);
168 static void cf_somequeue(int (*fn
)(disorder_client
*c
,
169 struct queue_entry
**qp
)) {
170 struct queue_entry
*q
;
172 if(fn(getclient(), &q
)) exit(EXIT_FAILURE
);
174 print_queue_entry(q
);
179 static void cf_recent(char attribute((unused
)) **argv
) {
180 cf_somequeue(disorder_recent
);
183 static void cf_queue(char attribute((unused
)) **argv
) {
184 cf_somequeue(disorder_queue
);
187 static void cf_quack(char attribute((unused
)) **argv
) {
189 " .------------------.\n"
190 " | Naath is a babe! |\n"
191 " `---------+--------'\n"
195 "~~~~~~~~~~~~~~~~~~~~~~\n"
199 static void cf_somelist(char **argv
,
200 int (*fn
)(disorder_client
*c
,
201 const char *arg
, const char *re
,
202 char ***vecp
, int *nvecp
)) {
207 re
= xstrdup(argv
[1] + 1);
210 if(fn(getclient(), argv
[0], re
, &vec
, 0)) exit(EXIT_FAILURE
);
212 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
215 static int isarg_regexp(const char *s
) {
219 static void cf_dirs(char **argv
) {
220 cf_somelist(argv
, disorder_directories
);
223 static void cf_files(char **argv
) {
224 cf_somelist(argv
, disorder_files
);
227 static void cf_allfiles(char **argv
) {
228 cf_somelist(argv
, disorder_allfiles
);
231 static void cf_get(char **argv
) {
234 if(disorder_get(getclient(), argv
[0], argv
[1], &value
)) exit(EXIT_FAILURE
);
235 xprintf("%s\n", nullcheck(utf82mb(value
)));
238 static void cf_length(char **argv
) {
241 if(disorder_length(getclient(), argv
[0], &length
)) exit(EXIT_FAILURE
);
242 xprintf("%ld\n", length
);
245 static void cf_set(char **argv
) {
246 if(disorder_set(getclient(), argv
[0], argv
[1], argv
[2])) exit(EXIT_FAILURE
);
249 static void cf_unset(char **argv
) {
250 if(disorder_unset(getclient(), argv
[0], argv
[1])) exit(EXIT_FAILURE
);
253 static void cf_prefs(char **argv
) {
256 if(disorder_prefs(getclient(), argv
[0], &k
)) exit(EXIT_FAILURE
);
257 for(; k
; k
= k
->next
)
259 nullcheck(utf82mb(k
->name
)), nullcheck(utf82mb(k
->value
)));
262 static void cf_search(char **argv
) {
266 if(disorder_search(getclient(), *argv
, &results
, &nresults
)) exit(EXIT_FAILURE
);
267 for(n
= 0; n
< nresults
; ++n
)
268 xprintf("%s\n", nullcheck(utf82mb(results
[n
])));
271 static void cf_random_disable(char attribute((unused
)) **argv
) {
272 if(disorder_random_disable(getclient())) exit(EXIT_FAILURE
);
275 static void cf_random_enable(char attribute((unused
)) **argv
) {
276 if(disorder_random_enable(getclient())) exit(EXIT_FAILURE
);
279 static void cf_stats(char attribute((unused
)) **argv
) {
282 if(disorder_stats(getclient(), &vec
, 0)) exit(EXIT_FAILURE
);
284 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
287 static void cf_get_volume(char attribute((unused
)) **argv
) {
290 if(disorder_get_volume(getclient(), &l
, &r
)) exit(EXIT_FAILURE
);
291 xprintf("%d %d\n", l
, r
);
294 static void cf_set_volume(char **argv
) {
295 if(disorder_set_volume(getclient(), atoi(argv
[0]), atoi(argv
[1]))) exit(EXIT_FAILURE
);
298 static void cf_log(char attribute((unused
)) **argv
) {
299 if(disorder_log(getclient(), sink_stdio("stdout", stdout
))) exit(EXIT_FAILURE
);
302 static void cf_move(char **argv
) {
306 if((e
= xstrtol(&n
, argv
[1], 0, 10)))
307 fatal(e
, "cannot convert '%s'", argv
[1]);
308 if(n
> INT_MAX
|| n
< INT_MIN
)
309 fatal(e
, "%ld out of range", n
);
310 if(disorder_move(getclient(), argv
[0], (int)n
)) exit(EXIT_FAILURE
);
313 static void cf_part(char **argv
) {
316 if(disorder_part(getclient(), &s
, argv
[0], argv
[1], argv
[2])) exit(EXIT_FAILURE
);
317 xprintf("%s\n", nullcheck(utf82mb(s
)));
320 static int isarg_filename(const char *s
) {
324 static void cf_authorize(char **argv
) {
325 authorize(getclient(), argv
[0], argv
[1]);
328 static void cf_resolve(char **argv
) {
331 if(disorder_resolve(getclient(), &track
, argv
[0])) exit(EXIT_FAILURE
);
332 xprintf("%s\n", nullcheck(utf82mb(track
)));
335 static void cf_pause(char attribute((unused
)) **argv
) {
336 if(disorder_pause(getclient())) exit(EXIT_FAILURE
);
339 static void cf_resume(char attribute((unused
)) **argv
) {
340 if(disorder_resume(getclient())) exit(EXIT_FAILURE
);
343 static void cf_tags(char attribute((unused
)) **argv
) {
346 if(disorder_tags(getclient(), &vec
, 0)) exit(EXIT_FAILURE
);
348 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
351 static void cf_users(char attribute((unused
)) **argv
) {
354 if(disorder_users(getclient(), &vec
, 0)) exit(EXIT_FAILURE
);
356 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
359 static void cf_get_global(char **argv
) {
362 if(disorder_get_global(getclient(), argv
[0], &value
)) exit(EXIT_FAILURE
);
363 xprintf("%s\n", nullcheck(utf82mb(value
)));
366 static void cf_set_global(char **argv
) {
367 if(disorder_set_global(getclient(), argv
[0], argv
[1])) exit(EXIT_FAILURE
);
370 static void cf_unset_global(char **argv
) {
371 if(disorder_unset_global(getclient(), argv
[0])) exit(EXIT_FAILURE
);
374 static int isarg_integer(const char *s
) {
377 if(!isdigit((unsigned char)*s
))
384 static void cf_new(char **argv
) {
387 if(disorder_new_tracks(getclient(), &vec
, 0, argv
[0] ?
atoi(argv
[0]) : 0))
390 xprintf("%s\n", nullcheck(utf82mb(*vec
++)));
393 static void cf_rtp_address(char attribute((unused
)) **argv
) {
394 char *address
, *port
;
396 if(disorder_rtp_address(getclient(), &address
, &port
)) exit(EXIT_FAILURE
);
397 xprintf("address: %s\nport: %s\n", address
, port
);
400 static int isarg_rights(const char *arg
) {
401 return strchr(arg
, ',') || !parse_rights(arg
, 0, 0);
404 static void cf_adduser(char **argv
) {
405 if(disorder_adduser(getclient(), argv
[0], argv
[1], argv
[2]))
409 static void cf_deluser(char **argv
) {
410 if(disorder_deluser(getclient(), argv
[0]))
414 static void cf_edituser(char **argv
) {
415 if(disorder_edituser(getclient(), argv
[0], argv
[1], argv
[2]))
419 static void cf_userinfo(char **argv
) {
422 if(disorder_userinfo(getclient(), argv
[0], argv
[1], &s
))
424 xprintf("%s\n", nullcheck(utf82mb(s
)));
427 static int isarg_option(const char *arg
) {
428 return arg
[0] == '-';
431 static int argvlen(char **argv
) {
439 static const struct option setup_guest_options
[] = {
440 { "help", no_argument
, 0, 'h' },
441 { "online-registration", no_argument
, 0, 'r' },
442 { "no-online-registration", no_argument
, 0, 'R' },
446 static void help_setup_guest(void) {
448 " disorder setup-guest [OPTIONS]\n"
450 " --help, -h Display usage message\n"
451 " --online-registration Enable online registration (default)\n"
452 " --no-online-registration Disable online registration\n");
457 static void cf_setup_guest(char **argv
) {
458 int n
, online_registration
= 1;
460 while((n
= getopt_long(argvlen(argv
) + 1, argv
- 1,
461 "hrR", setup_guest_options
, 0)) >= 0) {
463 case 'h': help_setup_guest();
464 case 'r': online_registration
= 1; break;
465 case 'R': online_registration
= 0; break;
466 default: fatal(0, "invalid option");
469 if(online_registration
&& !config
->mail_sender
)
470 fatal(0, "you MUST set mail_sender if you want online registration");
471 if(disorder_adduser(getclient(), "guest", "",
472 online_registration ?
"read,register" : "read"))
476 struct scheduled_event
{
478 struct kvp
*actiondata
;
482 static int compare_event(const void *av
, const void *bv
) {
483 struct scheduled_event
*a
= (void *)av
, *b
= (void *)bv
;
485 /* Primary sort key is the trigger time */
486 if(a
->when
< b
->when
)
488 else if(a
->when
> b
->when
)
490 /* For events that go off at the same time just sort by ID */
491 return strcmp(a
->id
, b
->id
);
494 static void cf_schedule_list(char attribute((unused
)) **argv
) {
497 struct scheduled_event
*events
;
499 const char *action
, *key
, *value
, *priority
;
502 /* Get all known events */
503 if(disorder_schedule_list(getclient(), &ids
, &nids
))
505 events
= xcalloc(nids
, sizeof *events
);
506 for(n
= 0; n
< nids
; ++n
) {
507 events
[n
].id
= ids
[n
];
508 if(disorder_schedule_get(getclient(), ids
[n
], &events
[n
].actiondata
))
510 events
[n
].when
= atoll(kvp_get(events
[n
].actiondata
, "when"));
512 /* Sort by trigger time */
513 qsort(events
, nids
, sizeof *events
, compare_event
);
515 for(n
= 0; n
< nids
; ++n
) {
516 strftime(tb
, sizeof tb
, "%Y-%m-%d %H:%M:%S %Z", localtime(&events
[n
].when
));
517 action
= kvp_get(events
[n
].actiondata
, "action");
518 priority
= kvp_get(events
[n
].actiondata
, "priority");
519 if(!strcmp(priority
, "junk"))
521 else if(!strcmp(priority
, "normal"))
525 xprintf("%11s %-25s %c %-8s %s",
526 events
[n
].id
, tb
, prichar
, kvp_get(events
[n
].actiondata
, "who"),
528 if(!strcmp(action
, "play"))
530 nullcheck(utf82mb(kvp_get(events
[n
].actiondata
, "track"))));
531 else if(!strcmp(action
, "set-global")) {
532 key
= kvp_get(events
[n
].actiondata
, "key");
533 value
= kvp_get(events
[n
].actiondata
, "value");
536 nullcheck(utf82mb(key
)),
537 nullcheck(utf82mb(value
)));
540 nullcheck(utf82mb(key
)));
546 static void cf_schedule_del(char **argv
) {
547 if(disorder_schedule_del(getclient(), argv
[0]))
551 static void cf_schedule_play(char **argv
) {
552 if(disorder_schedule_add(getclient(),
560 static void cf_schedule_set_global(char **argv
) {
561 if(disorder_schedule_add(getclient(),
570 static void cf_schedule_unset_global(char **argv
) {
571 if(disorder_schedule_add(getclient(),
580 static void cf_adopt(char **argv
) {
581 if(disorder_adopt(getclient(), argv
[0]))
585 static const struct command
{
589 int (*isarg
)(const char *);
590 const char *argstr
, *desc
;
592 { "adduser", 2, 3, cf_adduser
, isarg_rights
, "USERNAME PASSWORD [RIGHTS]",
593 "Create a new user" },
594 { "adopt", 1, 1, cf_adopt
, 0, "ID",
595 "Adopt a randomly picked track" },
596 { "allfiles", 1, 2, cf_allfiles
, isarg_regexp
, "DIR [~REGEXP]",
597 "List all files and directories in DIR" },
598 { "authorize", 1, 2, cf_authorize
, isarg_rights
, "USERNAME [RIGHTS]",
599 "Authorize user USERNAME to connect" },
600 { "deluser", 1, 1, cf_deluser
, 0, "USERNAME",
601 "Delete user USERNAME" },
602 { "dirs", 1, 2, cf_dirs
, isarg_regexp
, "DIR [~REGEXP]",
603 "List directories in DIR" },
604 { "disable", 0, 0, cf_disable
, 0, "",
606 { "disable-random", 0, 0, cf_random_disable
, 0, "",
607 "Disable random play" },
608 { "edituser", 3, 3, cf_edituser
, 0, "USERNAME PROPERTY VALUE",
609 "Set a property of user USERNAME" },
610 { "enable", 0, 0, cf_enable
, 0, "",
612 { "enable-random", 0, 0, cf_random_enable
, 0, "",
613 "Enable random play" },
614 { "files", 1, 2, cf_files
, isarg_regexp
, "DIR [~REGEXP]",
615 "List files in DIR" },
616 { "get", 2, 2, cf_get
, 0, "TRACK NAME",
617 "Get a preference value" },
618 { "get-global", 1, 1, cf_get_global
, 0, "NAME",
619 "Get a global preference value" },
620 { "get-volume", 0, 0, cf_get_volume
, 0, "",
621 "Get the current volume" },
622 { "length", 1, 1, cf_length
, 0, "TRACK",
623 "Get the length of TRACK in seconds" },
624 { "log", 0, 0, cf_log
, 0, "",
625 "Copy event log to stdout" },
626 { "move", 2, 2, cf_move
, 0, "TRACK DELTA",
627 "Move a track in the queue" },
628 { "new", 0, 1, cf_new
, isarg_integer
, "[MAX]",
629 "Get the most recently added MAX tracks" },
630 { "part", 3, 3, cf_part
, 0, "TRACK CONTEXT PART",
631 "Find a track name part" },
632 { "pause", 0, 0, cf_pause
, 0, "",
633 "Pause the currently playing track" },
634 { "play", 1, INT_MAX
, cf_play
, isarg_filename
, "TRACKS...",
635 "Add TRACKS to the end of the queue" },
636 { "playing", 0, 0, cf_playing
, 0, "",
637 "Report the playing track" },
638 { "prefs", 1, 1, cf_prefs
, 0, "TRACK",
639 "Display all the preferences for TRACK" },
640 { "quack", 0, 0, cf_quack
, 0, 0, 0 },
641 { "queue", 0, 0, cf_queue
, 0, "",
642 "Display the current queue" },
643 { "random-disable", 0, 0, cf_random_disable
, 0, "",
644 "Disable random play" },
645 { "random-enable", 0, 0, cf_random_enable
, 0, "",
646 "Enable random play" },
647 { "recent", 0, 0, cf_recent
, 0, "",
648 "Display recently played track" },
649 { "reconfigure", 0, 0, cf_reconfigure
, 0, "",
650 "Reconfigure the daemon" },
651 { "remove", 1, 1, cf_remove
, 0, "TRACK",
652 "Remove a track from the queue" },
653 { "rescan", 0, 0, cf_rescan
, 0, "",
654 "Rescan for new tracks" },
655 { "resolve", 1, 1, cf_resolve
, 0, "TRACK",
656 "Resolve alias for TRACK" },
657 { "resume", 0, 0, cf_resume
, 0, "",
658 "Resume after a pause" },
659 { "rtp-address", 0, 0, cf_rtp_address
, 0, "",
660 "Report server's broadcast address" },
661 { "schedule-del", 1, 1, cf_schedule_del
, 0, "EVENT",
662 "Delete a scheduled event" },
663 { "schedule-list", 0, 0, cf_schedule_list
, 0, "",
664 "List scheduled events" },
665 { "schedule-play", 3, 3, cf_schedule_play
, 0, "WHEN PRI TRACK",
666 "Play TRACK later" },
667 { "schedule-set-global", 4, 4, cf_schedule_set_global
, 0, "WHEN PRI NAME VAL",
668 "Set a global preference later" },
669 { "schedule-unset-global", 3, 3, cf_schedule_unset_global
, 0, "WHEN PRI NAME",
670 "Unset a global preference later" },
671 { "scratch", 0, 0, cf_scratch
, 0, "",
672 "Scratch the currently playing track" },
673 { "scratch-id", 1, 1, cf_scratch
, 0, "ID",
674 "Scratch the currently playing track" },
675 { "search", 1, 1, cf_search
, 0, "WORDS",
676 "Display tracks matching all the words" },
677 { "set", 3, 3, cf_set
, 0, "TRACK NAME VALUE",
678 "Set a preference value" },
679 { "set-global", 2, 2, cf_set_global
, 0, "NAME VALUE",
680 "Set a global preference value" },
681 { "set-volume", 2, 2, cf_set_volume
, 0, "LEFT RIGHT",
683 { "setup-guest", 0, INT_MAX
, cf_setup_guest
, isarg_option
, "[OPTIONS]",
684 "Create the guest login" },
685 { "shutdown", 0, 0, cf_shutdown
, 0, "",
686 "Shut down the daemon" },
687 { "stats", 0, 0, cf_stats
, 0, "",
688 "Display server statistics" },
689 { "tags", 0, 0, cf_tags
, 0, "",
691 { "unset", 2, 2, cf_unset
, 0, "TRACK NAME",
692 "Unset a preference" },
693 { "unset-global", 1, 1, cf_unset_global
, 0, "NAME",
694 "Unset a global preference" },
695 { "userinfo", 2, 2, cf_userinfo
, 0, "USERNAME PROPERTY",
696 "Get a property of a user" },
697 { "users", 0, 0, cf_users
, 0, "",
699 { "version", 0, 0, cf_version
, 0, "",
700 "Display the server version" },
703 static void help_commands(void) {
704 unsigned n
, max
= 0, l
;
706 xprintf("Command summary:\n");
707 for(n
= 0; n
< sizeof commands
/ sizeof *commands
; ++n
) {
708 if(!commands
[n
].desc
) continue;
709 l
= strlen(commands
[n
].name
);
710 if(*commands
[n
].argstr
)
711 l
+= strlen(commands
[n
].argstr
) + 1;
715 for(n
= 0; n
< sizeof commands
/ sizeof *commands
; ++n
) {
716 if(!commands
[n
].desc
) continue;
717 l
= strlen(commands
[n
].name
);
718 if(*commands
[n
].argstr
)
719 l
+= strlen(commands
[n
].argstr
) + 1;
720 xprintf(" %s%s%s%*s %s\n", commands
[n
].name
,
721 *commands
[n
].argstr ?
" " : "",
730 int main(int argc
, char **argv
) {
731 int n
, i
, j
, local
= 0;
734 const char *user
= 0, *password
= 0;
737 /* garbage-collect PCRE's memory */
738 pcre_malloc
= xmalloc
;
740 if(!setlocale(LC_CTYPE
, "")) fatal(errno
, "error calling setlocale");
741 if(!setlocale(LC_TIME
, "")) fatal(errno
, "error calling setlocale");
742 while((n
= getopt_long(argc
, argv
, "+hVc:dHlNu:p:", options
, 0)) >= 0) {
745 case 'H': help_commands();
746 case 'V': version("disorder");
747 case 'c': configfile
= optarg
; break;
748 case 'd': debugging
= 1; break;
749 case 'l': local
= 1; break;
750 case 'N': config_per_user
= 0; break;
751 case 'u': user
= optarg
; break;
752 case 'p': password
= optarg
; break;
753 default: fatal(0, "invalid option");
756 if(config_read(0)) fatal(0, "cannot read configuration");
758 config
->username
= user
;
759 config
->password
= 0;
762 config
->password
= password
;
764 config
->connect
.n
= 0;
766 optind
= 1; /* for subsequent getopt calls */
767 /* accumulate command args */
769 if((i
= TABLE_FIND(commands
, name
, argv
[n
])) < 0)
770 fatal(0, "unknown command '%s'", argv
[n
]);
771 if(n
+ commands
[i
].min
>= argc
)
772 fatal(0, "missing arguments to '%s'", argv
[n
]);
774 /* Include the command name in the args, but at element -1, for
775 * the benefit of subcommand getopt calls */
776 vector_append(&args
, argv
[n
]);
778 for(j
= 0; j
< commands
[i
].min
; ++j
)
779 vector_append(&args
, nullcheck(mb2utf8(argv
[n
+ j
])));
780 for(; j
< commands
[i
].max
782 && commands
[i
].isarg(argv
[n
+ j
]); ++j
)
783 vector_append(&args
, nullcheck(mb2utf8(argv
[n
+ j
])));
784 vector_terminate(&args
);
785 commands
[i
].fn(args
.vec
+ 1);
788 if(client
&& disorder_close(client
)) exit(EXIT_FAILURE
);
789 if(fclose(stdout
) < 0) fatal(errno
, "error closing stdout");