1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 int dispatch_verb(int argc, char *argv[], const Verb verbs[], void *userdata) {
32 assert(verbs[0].dispatch);
35 assert(argc >= optind);
43 /* At the end of the list? */
44 if (!verbs[i].dispatch) {
46 log_error("Unknown operation %s.", name);
48 log_error("Requires operation parameter.");
53 found = streq(name, verbs[i].verb);
55 found = !!(verbs[i].flags & VERB_DEFAULT);
68 if (verb->min_args != VERB_ANY &&
69 (unsigned) left < verb->min_args) {
70 log_error("Too few arguments.");
74 if (verb->max_args != VERB_ANY &&
75 (unsigned) left > verb->max_args) {
76 log_error("Too many arguments.");
81 return verb->dispatch(left, argv + optind, userdata);
88 return verb->dispatch(1, fake, userdata);