DEADSOFTWARE

update copyrights
[flatwaifu.git] / src / args.c
1 /* Copyright (C) 2020 SovietPony
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 */
16 #include "args.h"
17 #include "system.h"
18 #include "error.h"
19 #include "config.h"
20 #include <assert.h>
22 void ARG_parse (int argc, char **argv, int n, const cfg_t **list) {
23 assert(argc >= 0);
24 assert(argv != NULL);
25 assert(n >= 0);
26 assert(list != NULL);
27 int i, j;
28 char *key;
29 const cfg_t *c;
30 for (i = 1; i < argc; i++) {
31 if (argv[i][0] == '-' && argv[i][1] != 0) {
32 j = 0;
33 c = NULL;
34 key = &argv[i][1];
35 while (j < n && c == NULL){
36 c = CFG_find_entry(key, list[j]);
37 j++;
38 }
39 if (c == NULL) {
40 ERR_failinit("%s: unknown parameter %s\n", argv[0], argv[i]);
41 } else if (c->t == Y_SW_ON || c->t == Y_SW_OFF) {
42 CFG_update_key(key, "on", c);
43 } else if (i + 1 < argc) {
44 CFG_update_key(key, argv[i + 1], c);
45 i += 1;
46 } else {
47 ERR_failinit("%s: missing argument for parameter %s\n", argv[0], argv[i]);
48 }
49 } else {
50 ERR_failinit("%s: something wrong here: %s\n", argv[0], argv[i]);
51 }
52 }
53 }