annotate pwmrc.c @ 32:b5ebed168e59

Only invoke pager in the help command for the summary of all commands Display usage information for a single command directly and prefix it with "usage:" like usage error messages.
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Tue, 28 Nov 2017 17:16:24 +0100
parents 2552eec9b913
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
1 /*
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
2 * Copyright (C) 2017 Guido Berhoerster <guido+pwm@berhoerster.name>
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
3 *
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
4 * Permission is hereby granted, free of charge, to any person obtaining
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
5 * a copy of this software and associated documentation files (the
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
6 * "Software"), to deal in the Software without restriction, including
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
7 * without limitation the rights to use, copy, modify, merge, publish,
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
8 * distribute, sublicense, and/or sell copies of the Software, and to
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
9 * permit persons to whom the Software is furnished to do so, subject to
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
10 * the following conditions:
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
11 *
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
12 * The above copyright notice and this permission notice shall be included
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
13 * in all copies or substantial portions of the Software.
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
14 *
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
22 */
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
23
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
24 #include "compat.h"
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
25
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
26 #include <errno.h>
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
27 #include <fcntl.h>
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
28 #ifdef HAVE_ERR_H
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
29 #include <err.h>
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
30 #endif /* HAVE_ERR_H */
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
31 #include <stdio.h>
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
32 #include <stdlib.h>
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
33 #include <string.h>
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
34 #include <sys/stat.h>
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
35 #include <unistd.h>
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
36
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
37 #include "pwm.h"
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
38 #include "cmd.h"
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
39 #include "io.h"
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
40 #include "macro.h"
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
41 #include "tok.h"
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
42 #include "util.h"
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
43
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
44 static const char *config_cmds[] = {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
45 "set",
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
46 "define"
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
47 };
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
48
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
49 int
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
50 pwmrc_read(struct pwm_ctx *ctx)
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
51 {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
52 int retval = -1;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
53 char *filename = NULL;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
54 FILE *fp = NULL;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
55 int lineno;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
56 char buf[PWM_LINE_MAX] = { '\0' };
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
57 size_t tokenc = 0;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
58 union tok **tokenv = NULL;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
59 int argc = 0;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
60 char **argv = NULL;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
61 struct cmd *cmd;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
62 size_t i;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
63 int is_config_cmd;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
64 int j;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
65
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
66 xasprintf(&filename, "%s/pwmrc", ctx->dirname);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
67
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
68 fp = fopen(filename, "r");
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
69 if (fp == NULL) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
70 if (errno == ENOENT) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
71 retval = 0;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
72 } else {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
73 warn("failed to open configuration file \"%s\"",
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
74 filename);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
75 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
76 goto out;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
77 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
78
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
79 for (lineno = 1;; lineno++) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
80 /* read next line */
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
81 is_config_cmd = 0;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
82 if (fgets(buf, sizeof (buf), fp) == NULL) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
83 if (feof(fp)) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
84 goto done;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
85 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
86 warn("failed to read from configuration file \"%s\"",
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
87 filename);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
88 goto out;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
89 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
90 if (strchr(buf, '\n') == NULL) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
91 fprintf(stderr, "line %d too long\n", lineno);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
92 goto out;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
93 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
94
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
95 /* tokenize line */
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
96 switch (tok_tokenize(buf, &tokenc, &tokenv)) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
97 case TOK_ERR_UNTERMINATED_QUOTE:
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
98 fprintf(stderr, "unterminated quote in line %d\n",
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
99 lineno);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
100 if (!ctx->is_interactive) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
101 goto out;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
102 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
103 goto next;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
104 case TOK_ERR_TRAILING_BACKSLASH:
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
105 fprintf(stderr, "trailing backslash in line %d\n",
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
106 lineno);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
107 if (!ctx->is_interactive) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
108 goto out;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
109 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
110 goto next;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
111 case TOK_ERR_INVALID_MACRO_NAME:
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
112 fprintf(stderr, "invalid macro name in line %d\n",
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
113 lineno);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
114 if (!ctx->is_interactive) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
115 goto out;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
116 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
117 goto next;
30
2552eec9b913 Explicitly handle all cases in switch statements
Guido Berhoerster <guido+pwm@berhoerster.name>
parents: 29
diff changeset
118 case TOK_ERR_OK:
2552eec9b913 Explicitly handle all cases in switch statements
Guido Berhoerster <guido+pwm@berhoerster.name>
parents: 29
diff changeset
119 break;
29
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
120 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
121
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
122 /* expand macros */
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
123 if (macro_expand_macros(ctx->macro_head, tokenc, tokenv, &argc,
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
124 &argv) != 0) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
125 fprintf(stderr, "undefined macro in line %d\n", lineno);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
126 if (!ctx->is_interactive) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
127 goto out;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
128 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
129 goto next;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
130 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
131
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
132 if (argc == 0) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
133 /* empty line */
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
134 goto next;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
135 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
136
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
137 /* find and execute the command */
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
138 cmd = cmd_match(argv[0]);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
139 for (i = 0; (cmd != NULL) && (i < COUNTOF(config_cmds)); i++) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
140 if (strcmp(cmd->full_cmd, config_cmds[i]) == 0) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
141 is_config_cmd = 1;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
142 break;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
143 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
144 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
145 if (!is_config_cmd) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
146 fprintf(stderr, "unknown configuration command \"%s\""
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
147 " in line %d\n", argv[0], lineno);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
148 goto out;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
149 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
150 if (cmd->cmd_func(ctx, argc, argv) != CMD_OK) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
151 fprintf(stderr, "syntax error in line %d\n", lineno);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
152 goto out;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
153 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
154
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
155 next:
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
156 for (j = 0; j < argc; j++) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
157 free(argv[j]);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
158 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
159 free(argv);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
160 argc = 0;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
161 argv = NULL;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
162 tok_free(tokenv);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
163 tokenc = 0;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
164 tokenv = NULL;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
165 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
166
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
167 done:
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
168 retval = 0;
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
169
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
170 out:
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
171 for (j = 0; j < argc; j++) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
172 free(argv[j]);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
173 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
174 free(argv);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
175 tok_free(tokenv);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
176 if (fp != NULL) {
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
177 fclose(fp);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
178 }
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
179 free(filename);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
180
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
181 return (retval);
00d782cb45fa Read configuration file on startup
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff changeset
182 }