2 This file is part of GNUnet.
3 Copyright (C) 2013-2019 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
26 static const char *usage_note =
28 "Scan a QR code using a video device and import\n"
30 "Arguments mandatory for long options are also mandatory for short options.\n"
31 " -c, --config FILENAME use configuration file FILENAME\n"
32 " -d, --device DEVICE use device DEVICE\n"
33 " -s, --silent do not show preview windows\n"
34 " -h, --help print this help\n"
35 " -v, --verbose be verbose\n"
36 "Report bugs to gnunet-developers@gnu.org.\n"
38 "GNUnet home page: https://gnunet.org/\n"
39 "General help using GNU software: https://www.gnu.org/gethelp/\n";
41 #define LOG(fmt, ...) if (verbose == true) printf(fmt, ## __VA_ARGS__)
43 int main (int argc, char **argv)
45 const char* configuration = NULL;
46 const char* device = "/dev/video0";
47 static bool verbose = false;
48 static bool silent = false;
50 static struct option long_options[] = {
51 {"verbose", no_argument, 0, 'v'},
52 {"silent", no_argument, 0, 's'},
53 {"help", no_argument, 0, 'h'},
54 {"config", required_argument, 0, 'c'},
55 {"device", required_argument, 0, 'd'},
60 opt = getopt_long (argc, argv, "c:hd:sv",
70 configuration = optarg;
87 /* create a Processor */
88 LOG("Initializing\n");
89 zbar_processor_t *proc = zbar_processor_create(1);
91 // FIXME: Wrap all this into a function which returns an error on
92 // failure. And here ensure the processor is destroyed at the end.
94 /* configure the Processor */
95 zbar_processor_parse_config(proc, "enable");
97 /* initialize the Processor */
98 LOG("Opening video device %s\n", device);
99 // FIXME: error handling
100 zbar_processor_init(proc, device, 1);
102 /* enable the preview window */
103 zbar_processor_set_visible(proc, 1);
104 zbar_processor_set_active(proc, 1);
106 /* keep scanning until user provides key/mouse input */
107 //zbar_processor_user_wait(proc, -1);
109 // read at least one barcode (or until window closed)
112 n = zbar_process_one(proc, -1);
113 LOG("Got %i images\n", n);
114 // FIXME: Error handling (n = -1)
116 // hide the preview window
117 zbar_processor_set_active(proc, 0);
118 zbar_processor_set_visible(proc, 0);
123 const zbar_symbol_set_t* symbols = zbar_processor_get_results(proc);
124 const zbar_symbol_t* symbol = zbar_symbol_set_first_symbol(symbols);
126 if (symbol != NULL) {
127 const char* data = zbar_symbol_get_data(symbol);
128 LOG("Found %s \"%s\"\n",
129 zbar_get_symbol_name(zbar_symbol_get_type(symbol)), data);
132 args = ["gnunet-uri",
133 // FIXME: "-c", configuration,
135 if (verbose = true) {
136 // TODO: print arguments:
137 printf("Running `%s %s %s %s`", *args, "", ""); // FIXME variable num args
139 rc = popen("gnunet-uri", *args);
142 printf("Failed to add URI %s\n", data);
144 printf("Added URI %s\n", data);
149 zbar_processor_destroy(proc);