diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/util/gnunet-qr.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/util/gnunet-qr.c')
-rw-r--r-- | src/util/gnunet-qr.c | 258 |
1 files changed, 129 insertions, 129 deletions
diff --git a/src/util/gnunet-qr.c b/src/util/gnunet-qr.c index ff781f726..91c36dbdf 100644 --- a/src/util/gnunet-qr.c +++ b/src/util/gnunet-qr.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file util/gnunet-qr.c | 21 | * @file util/gnunet-qr.c |
22 | * @author Hartmut Goebel (original implementation) | 22 | * @author Hartmut Goebel (original implementation) |
@@ -31,7 +31,7 @@ | |||
31 | 31 | ||
32 | #define LOG(fmt, ...) \ | 32 | #define LOG(fmt, ...) \ |
33 | if (verbose == true) \ | 33 | if (verbose == true) \ |
34 | printf (fmt, ##__VA_ARGS__) | 34 | printf (fmt, ## __VA_ARGS__) |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Video device to capture from. Sane default for GNU/Linux systems. | 37 | * Video device to capture from. Sane default for GNU/Linux systems. |
@@ -72,14 +72,14 @@ static struct GNUNET_DISK_PipeHandle *sigpipe; | |||
72 | * @param cls closure, NULL | 72 | * @param cls closure, NULL |
73 | */ | 73 | */ |
74 | static void | 74 | static void |
75 | maint_child_death (void *cls) | 75 | maint_child_death(void *cls) |
76 | { | 76 | { |
77 | enum GNUNET_OS_ProcessStatusType type; | 77 | enum GNUNET_OS_ProcessStatusType type; |
78 | 78 | ||
79 | if ((GNUNET_OK != GNUNET_OS_process_status (p, &type, &exit_code)) || | 79 | if ((GNUNET_OK != GNUNET_OS_process_status(p, &type, &exit_code)) || |
80 | (type != GNUNET_OS_PROCESS_EXITED)) | 80 | (type != GNUNET_OS_PROCESS_EXITED)) |
81 | GNUNET_break (0 == GNUNET_OS_process_kill (p, GNUNET_TERM_SIG)); | 81 | GNUNET_break(0 == GNUNET_OS_process_kill(p, GNUNET_TERM_SIG)); |
82 | GNUNET_OS_process_destroy (p); | 82 | GNUNET_OS_process_destroy(p); |
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
@@ -92,10 +92,10 @@ maint_child_death (void *cls) | |||
92 | * @param cfg configuration | 92 | * @param cfg configuration |
93 | */ | 93 | */ |
94 | static void | 94 | static void |
95 | gnunet_uri (void *cls, | 95 | gnunet_uri(void *cls, |
96 | const char *uri, | 96 | const char *uri, |
97 | const char *cfgfile, | 97 | const char *cfgfile, |
98 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 98 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
99 | { | 99 | { |
100 | const char *orig_uri; | 100 | const char *orig_uri; |
101 | const char *slash; | 101 | const char *slash; |
@@ -104,45 +104,45 @@ gnunet_uri (void *cls, | |||
104 | struct GNUNET_SCHEDULER_Task *rt; | 104 | struct GNUNET_SCHEDULER_Task *rt; |
105 | 105 | ||
106 | orig_uri = uri; | 106 | orig_uri = uri; |
107 | if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://"))) | 107 | if (0 != strncasecmp("gnunet://", uri, strlen("gnunet://"))) |
108 | { | 108 | { |
109 | fprintf (stderr, | 109 | fprintf(stderr, |
110 | _ ("Invalid URI: does not start with `%s'\n"), | 110 | _("Invalid URI: does not start with `%s'\n"), |
111 | "gnunet://"); | 111 | "gnunet://"); |
112 | return; | 112 | return; |
113 | } | 113 | } |
114 | uri += strlen ("gnunet://"); | 114 | uri += strlen("gnunet://"); |
115 | if (NULL == (slash = strchr (uri, '/'))) | 115 | if (NULL == (slash = strchr(uri, '/'))) |
116 | { | 116 | { |
117 | fprintf (stderr, _ ("Invalid URI: fails to specify subsystem\n")); | 117 | fprintf(stderr, _("Invalid URI: fails to specify subsystem\n")); |
118 | return; | 118 | return; |
119 | } | 119 | } |
120 | subsystem = GNUNET_strndup (uri, slash - uri); | 120 | subsystem = GNUNET_strndup(uri, slash - uri); |
121 | if (GNUNET_OK != | 121 | if (GNUNET_OK != |
122 | GNUNET_CONFIGURATION_get_value_string (cfg, "uri", subsystem, &program)) | 122 | GNUNET_CONFIGURATION_get_value_string(cfg, "uri", subsystem, &program)) |
123 | { | 123 | { |
124 | fprintf (stderr, _ ("No handler known for subsystem `%s'\n"), subsystem); | 124 | fprintf(stderr, _("No handler known for subsystem `%s'\n"), subsystem); |
125 | GNUNET_free (subsystem); | 125 | GNUNET_free(subsystem); |
126 | return; | 126 | return; |
127 | } | 127 | } |
128 | GNUNET_free (subsystem); | 128 | GNUNET_free(subsystem); |
129 | rt = GNUNET_SCHEDULER_add_read_file ( | 129 | rt = GNUNET_SCHEDULER_add_read_file( |
130 | GNUNET_TIME_UNIT_FOREVER_REL, | 130 | GNUNET_TIME_UNIT_FOREVER_REL, |
131 | GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), | 131 | GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ), |
132 | &maint_child_death, | 132 | &maint_child_death, |
133 | NULL); | 133 | NULL); |
134 | p = GNUNET_OS_start_process (GNUNET_NO, | 134 | p = GNUNET_OS_start_process(GNUNET_NO, |
135 | 0, | 135 | 0, |
136 | NULL, | 136 | NULL, |
137 | NULL, | 137 | NULL, |
138 | NULL, | 138 | NULL, |
139 | program, | 139 | program, |
140 | program, | 140 | program, |
141 | orig_uri, | 141 | orig_uri, |
142 | NULL); | 142 | NULL); |
143 | GNUNET_free (program); | 143 | GNUNET_free(program); |
144 | if (NULL == p) | 144 | if (NULL == p) |
145 | GNUNET_SCHEDULER_cancel (rt); | 145 | GNUNET_SCHEDULER_cancel(rt); |
146 | } | 146 | } |
147 | 147 | ||
148 | 148 | ||
@@ -153,54 +153,54 @@ gnunet_uri (void *cls, | |||
153 | * @return NULL on error | 153 | * @return NULL on error |
154 | */ | 154 | */ |
155 | static const zbar_symbol_t * | 155 | static const zbar_symbol_t * |
156 | get_symbol (zbar_processor_t *proc) | 156 | get_symbol(zbar_processor_t *proc) |
157 | { | 157 | { |
158 | const zbar_symbol_set_t *symbols; | 158 | const zbar_symbol_set_t *symbols; |
159 | int rc; | 159 | int rc; |
160 | int n; | 160 | int n; |
161 | 161 | ||
162 | if (0 != zbar_processor_parse_config (proc, "enable")) | 162 | if (0 != zbar_processor_parse_config(proc, "enable")) |
163 | { | 163 | { |
164 | GNUNET_break (0); | 164 | GNUNET_break(0); |
165 | return NULL; | 165 | return NULL; |
166 | } | 166 | } |
167 | 167 | ||
168 | /* initialize the Processor */ | 168 | /* initialize the Processor */ |
169 | if (0 != (rc = zbar_processor_init (proc, device, 1))) | 169 | if (0 != (rc = zbar_processor_init(proc, device, 1))) |
170 | { | 170 | { |
171 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 171 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
172 | "Failed to open device `%s': %d\n", | 172 | "Failed to open device `%s': %d\n", |
173 | device, | 173 | device, |
174 | rc); | 174 | rc); |
175 | return NULL; | 175 | return NULL; |
176 | } | 176 | } |
177 | 177 | ||
178 | /* enable the preview window */ | 178 | /* enable the preview window */ |
179 | if ((0 != (rc = zbar_processor_set_visible (proc, 1))) || | 179 | if ((0 != (rc = zbar_processor_set_visible(proc, 1))) || |
180 | (0 != (rc = zbar_processor_set_active (proc, 1)))) | 180 | (0 != (rc = zbar_processor_set_active(proc, 1)))) |
181 | { | 181 | { |
182 | GNUNET_break (0); | 182 | GNUNET_break(0); |
183 | return NULL; | 183 | return NULL; |
184 | } | 184 | } |
185 | 185 | ||
186 | /* read at least one barcode (or until window closed) */ | 186 | /* read at least one barcode (or until window closed) */ |
187 | LOG ("Capturing\n"); | 187 | LOG("Capturing\n"); |
188 | n = zbar_process_one (proc, -1); | 188 | n = zbar_process_one(proc, -1); |
189 | 189 | ||
190 | /* hide the preview window */ | 190 | /* hide the preview window */ |
191 | (void) zbar_processor_set_active (proc, 0); | 191 | (void)zbar_processor_set_active(proc, 0); |
192 | (void) zbar_processor_set_visible (proc, 0); | 192 | (void)zbar_processor_set_visible(proc, 0); |
193 | if (-1 == n) | 193 | if (-1 == n) |
194 | return NULL; /* likely user closed the window */ | 194 | return NULL; /* likely user closed the window */ |
195 | LOG ("Got %i images\n", n); | 195 | LOG("Got %i images\n", n); |
196 | /* extract results */ | 196 | /* extract results */ |
197 | symbols = zbar_processor_get_results (proc); | 197 | symbols = zbar_processor_get_results(proc); |
198 | if (NULL == symbols) | 198 | if (NULL == symbols) |
199 | { | 199 | { |
200 | GNUNET_break (0); | 200 | GNUNET_break(0); |
201 | return NULL; | 201 | return NULL; |
202 | } | 202 | } |
203 | return zbar_symbol_set_first_symbol (symbols); | 203 | return zbar_symbol_set_first_symbol(symbols); |
204 | } | 204 | } |
205 | 205 | ||
206 | 206 | ||
@@ -210,7 +210,7 @@ get_symbol (zbar_processor_t *proc) | |||
210 | * @return NULL on error, otherwise the URI that we found | 210 | * @return NULL on error, otherwise the URI that we found |
211 | */ | 211 | */ |
212 | static char * | 212 | static char * |
213 | run_zbar () | 213 | run_zbar() |
214 | { | 214 | { |
215 | zbar_processor_t *proc; | 215 | zbar_processor_t *proc; |
216 | const char *data; | 216 | const char *data; |
@@ -218,32 +218,32 @@ run_zbar () | |||
218 | const zbar_symbol_t *symbol; | 218 | const zbar_symbol_t *symbol; |
219 | 219 | ||
220 | /* configure the Processor */ | 220 | /* configure the Processor */ |
221 | proc = zbar_processor_create (1); | 221 | proc = zbar_processor_create(1); |
222 | if (NULL == proc) | 222 | if (NULL == proc) |
223 | { | 223 | { |
224 | GNUNET_break (0); | 224 | GNUNET_break(0); |
225 | return NULL; | 225 | return NULL; |
226 | } | 226 | } |
227 | 227 | ||
228 | symbol = get_symbol (proc); | 228 | symbol = get_symbol(proc); |
229 | if (NULL == symbol) | 229 | if (NULL == symbol) |
230 | { | 230 | { |
231 | zbar_processor_destroy (proc); | 231 | zbar_processor_destroy(proc); |
232 | return NULL; | 232 | return NULL; |
233 | } | 233 | } |
234 | data = zbar_symbol_get_data (symbol); | 234 | data = zbar_symbol_get_data(symbol); |
235 | if (NULL == data) | 235 | if (NULL == data) |
236 | { | 236 | { |
237 | GNUNET_break (0); | 237 | GNUNET_break(0); |
238 | zbar_processor_destroy (proc); | 238 | zbar_processor_destroy(proc); |
239 | return NULL; | 239 | return NULL; |
240 | } | 240 | } |
241 | LOG ("Found %s \"%s\"\n", | 241 | LOG("Found %s \"%s\"\n", |
242 | zbar_get_symbol_name (zbar_symbol_get_type (symbol)), | 242 | zbar_get_symbol_name(zbar_symbol_get_type(symbol)), |
243 | data); | 243 | data); |
244 | ret = GNUNET_strdup (data); | 244 | ret = GNUNET_strdup(data); |
245 | /* clean up */ | 245 | /* clean up */ |
246 | zbar_processor_destroy (proc); | 246 | zbar_processor_destroy(proc); |
247 | return ret; | 247 | return ret; |
248 | } | 248 | } |
249 | 249 | ||
@@ -257,55 +257,55 @@ run_zbar () | |||
257 | * @param cfg configuration | 257 | * @param cfg configuration |
258 | */ | 258 | */ |
259 | static void | 259 | static void |
260 | run (void *cls, | 260 | run(void *cls, |
261 | char *const *args, | 261 | char *const *args, |
262 | const char *cfgfile, | 262 | const char *cfgfile, |
263 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 263 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
264 | { | 264 | { |
265 | char *data; | 265 | char *data; |
266 | 266 | ||
267 | data = run_zbar (); | 267 | data = run_zbar(); |
268 | if (NULL == data) | 268 | if (NULL == data) |
269 | return; | 269 | return; |
270 | gnunet_uri (cls, data, cfgfile, cfg); | 270 | gnunet_uri(cls, data, cfgfile, cfg); |
271 | if (exit_code != 0) | 271 | if (exit_code != 0) |
272 | { | 272 | { |
273 | printf ("Failed to add URI %s\n", data); | 273 | printf("Failed to add URI %s\n", data); |
274 | } | 274 | } |
275 | else | 275 | else |
276 | { | 276 | { |
277 | printf ("Added URI %s\n", data); | 277 | printf("Added URI %s\n", data); |
278 | } | 278 | } |
279 | GNUNET_free (data); | 279 | GNUNET_free(data); |
280 | }; | 280 | }; |
281 | 281 | ||
282 | 282 | ||
283 | int | 283 | int |
284 | main (int argc, char *const *argv) | 284 | main(int argc, char *const *argv) |
285 | { | 285 | { |
286 | int ret; | 286 | int ret; |
287 | struct GNUNET_GETOPT_CommandLineOption options[] = | 287 | struct GNUNET_GETOPT_CommandLineOption options[] = |
288 | {GNUNET_GETOPT_option_string ( | 288 | { GNUNET_GETOPT_option_string( |
289 | 'd', | 289 | 'd', |
290 | "device", | 290 | "device", |
291 | "DEVICE", | 291 | "DEVICE", |
292 | gettext_noop ("use video-device DEVICE (default: /dev/video0"), | 292 | gettext_noop("use video-device DEVICE (default: /dev/video0"), |
293 | &device), | 293 | &device), |
294 | GNUNET_GETOPT_option_flag ('\0', | 294 | GNUNET_GETOPT_option_flag('\0', |
295 | "verbose", | 295 | "verbose", |
296 | gettext_noop ("be verbose"), | 296 | gettext_noop("be verbose"), |
297 | &verbose), | 297 | &verbose), |
298 | GNUNET_GETOPT_option_flag ('s', | 298 | GNUNET_GETOPT_option_flag('s', |
299 | "silent", | 299 | "silent", |
300 | gettext_noop ("do not show preview windows"), | 300 | gettext_noop("do not show preview windows"), |
301 | &silent), | 301 | &silent), |
302 | GNUNET_GETOPT_OPTION_END}; | 302 | GNUNET_GETOPT_OPTION_END }; |
303 | 303 | ||
304 | ret = GNUNET_PROGRAM_run ( | 304 | ret = GNUNET_PROGRAM_run( |
305 | argc, | 305 | argc, |
306 | argv, | 306 | argv, |
307 | "gnunet-qr", | 307 | "gnunet-qr", |
308 | gettext_noop ( | 308 | gettext_noop( |
309 | "Scan a QR code using a video device and import the uri read"), | 309 | "Scan a QR code using a video device and import the uri read"), |
310 | options, | 310 | options, |
311 | &run, | 311 | &run, |