[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] 10/30: gnunet-qr: Use GNUNET_PROGRAM_run to simpli
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] 10/30: gnunet-qr: Use GNUNET_PROGRAM_run to simplify the code. |
Date: |
Wed, 03 Apr 2019 13:53:51 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
commit e14a51a2bb759429cb624cf4eba59454b6af24e7
Author: Hartmut Goebel <address@hidden>
AuthorDate: Sun Mar 3 22:08:53 2019 +0100
gnunet-qr: Use GNUNET_PROGRAM_run to simplify the code.
---
src/util/Makefile.am | 3 ++
src/util/gnunet-qr.c | 115 ++++++++++++++++++++++-----------------------------
2 files changed, 53 insertions(+), 65 deletions(-)
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 98997efbd..89d0462c5 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -282,6 +282,9 @@ gnunet_uri_LDADD = \
gnunet_qr_SOURCES = \
gnunet-qr.c \
gnunet-qr-utils.h
+gnunet_qr_LDADD = \
+ libgnunetutil.la \
+ $(GN_LIBINTL)
gnunet_qr_LDFLAGS= $(libzbar_LIBS)
gnunet_qr_CFLAGS = $(libzbar_CFLAGS) -DBINDIR=\"@bindir@/\"
diff --git a/src/util/gnunet-qr.c b/src/util/gnunet-qr.c
index ea0e0fea2..b54f352d5 100644
--- a/src/util/gnunet-qr.c
+++ b/src/util/gnunet-qr.c
@@ -21,70 +21,34 @@
#include <stdio.h>
#include <zbar.h>
#include <stdbool.h>
-#include <getopt.h>
+#include "platform.h"
+#include "gnunet_util_lib.h"
#include "gnunet-qr-utils.h"
-static const char *usage_note =
- "gnunet-qr\n"
- "Scan a QR code using a video device and import\n"
- "\n"
- "Arguments mandatory for long options are also mandatory for short
options.\n"
- " -c, --config FILENAME use configuration file FILENAME\n"
- " -d, --device DEVICE use device DEVICE\n"
- " -s, --silent do not show preview windows\n"
- " -h, --help print this help\n"
- " -v, --verbose be verbose\n"
- "Report bugs to address@hidden"
- "\n"
- "GNUnet home page: https://gnunet.org/\n"
- "General help using GNU software: https://www.gnu.org/gethelp/\n";
-
#define LOG(fmt, ...) if (verbose == true) printf(fmt, ## __VA_ARGS__)
-int main (int argc, char **argv)
+// Command line options
+// program exit code
+static long unsigned int exit_code = 1;
+
+static char* device = "/dev/video0";
+static int verbose = false;
+static int silent = false;
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be
NULL!)
+ * @param cfg configuration
+ */
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- const char* configuration = NULL;
- const char* device = "/dev/video0";
- static bool verbose = false;
- static bool silent = false;
-
- static struct option long_options[] = {
- {"verbose", no_argument, 0, 'v'},
- {"silent", no_argument, 0, 's'},
- {"help", no_argument, 0, 'h'},
- {"config", required_argument, 0, 'c'},
- {"device", required_argument, 0, 'd'},
- {0, 0, 0, 0}
- };
- while (1) {
- int opt;
- opt = getopt_long (argc, argv, "c:hd:sv",
- long_options, NULL);
- if (opt == -1)
- break;
-
- switch (opt) {
- case 'h':
- printf(usage_note);
- return 0;
- case 'c':
- configuration = optarg;
- break;
- case 'd':
- device = optarg;
- break;
- case 's':
- silent = true;
- break;
- case 'v':
- verbose = true;
- break;
- default:
- printf(usage_note);
- return 1;
- }
- }
-
/* create a Processor */
LOG("Initializing\n");
zbar_processor_t *proc = zbar_processor_create(1);
@@ -119,8 +83,6 @@ int main (int argc, char **argv)
zbar_processor_set_visible(proc, 0);
// extract results
- int rc = 1;
-
const zbar_symbol_set_t* symbols = zbar_processor_get_results(proc);
const zbar_symbol_t* symbol = zbar_symbol_set_first_symbol(symbols);
@@ -132,14 +94,14 @@ int main (int argc, char **argv)
if (configuration == NULL) {
char* command_args[] = {"gnunet-uri", data, NULL };
LOG("Running `gnunet-uri %s`\n", data);
- rc = fork_and_exec(BINDIR "gnunet-uri", command_args);
+ exit_code = fork_and_exec(BINDIR "gnunet-uri", command_args);
} else {
char* command_args[] = {"gnunet-uri", "-c", configuration, data, NULL };
LOG("Running `gnunet-uri -c '%s' %s`\n", configuration, data);
- rc = fork_and_exec(BINDIR "gnunet-uri", command_args);
+ exit_code = fork_and_exec(BINDIR "gnunet-uri", command_args);
};
- if (rc != 0) {
+ if (exit_code != 0) {
printf("Failed to add URI %s\n", data);
} else {
printf("Added URI %s\n", data);
@@ -148,6 +110,29 @@ int main (int argc, char **argv)
/* clean up */
zbar_processor_destroy(proc);
+};
- return(rc);
+
+int
+main (int argc, char *const *argv)
+{
+ static int ret;
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_string ('d', "device", "DEVICE",
+ gettext_noop ("use video-device DEVICE (default: /dev/video0"),
+ &device),
+ GNUNET_GETOPT_option_flag ('\0', "verbose",
+ gettext_noop ("be verbose"),
+ &verbose),
+ GNUNET_GETOPT_option_flag ('s', "silent",
+ gettext_noop ("do not show preview windows"),
+ &silent),
+ GNUNET_GETOPT_OPTION_END
+ };
+ ret = GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-qr",
+ gettext_noop ("Scan a QR code using a video device
and import the uri read"),
+ options, &run, NULL);
+ return ((GNUNET_OK == ret) && (0 == exit_code)) ? 0 : 1;
}
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnunet] branch master updated (65c86ea8d -> f256a930e), gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 04/30: gnunet-qr: Actually run gnunet-uri., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 06/30: configure.ac: Add check for libzbar (using pkgconfig)., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 02/30: gnunet-qr: Simplify verbose messaging., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 05/30: Add Hartmut Goebel to the AUTHORS file., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 10/30: gnunet-qr: Use GNUNET_PROGRAM_run to simplify the code.,
gnunet <=
- [GNUnet-SVN] [gnunet] 03/30: Add helper lib "gnunet-qr-utils.h"., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 07/30: gnunet-qr: Add into Makefile.am and pofiles,, gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 01/30: gnunet-qr: Reimplement in C - yet only a proof of concept., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 25/30: contrib/guix: Add zbar as dependency for package gnunet., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 17/30: gnunet-qr: Actually run gnunet-uri., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 15/30: gnunet-qr: Simplify verbose messaging., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 18/30: Add Hartmut Goebel to the AUTHORS file., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 08/30: gnunet-qr: Use the `gnunet-uri` binary installed into PREFIX., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 12/30: contrib/guix: Add zbar as dependency for package gnunet., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 09/30: gnunet-qr: Update documentation and scripts to changed dependencies., gnunet, 2019/04/03