From 0fde3f330fafce581aa1d8ff0500ccc284083882 Mon Sep 17 00:00:00 2001 From: Alexander Vdolainen Date: Wed, 9 Mar 2016 23:51:28 +0200 Subject: [PATCH] [examples] code cleanup; --- examples/filelistc.c | 10 ++-------- examples/helpers.h | 10 +++++++++- examples/smpfd.c | 11 ++--------- examples/streamflc.c | 10 ++-------- examples/streamfld.c | 11 ++--------- 5 files changed, 17 insertions(+), 35 deletions(-) diff --git a/examples/filelistc.c b/examples/filelistc.c index a62a791..2ec55d6 100644 --- a/examples/filelistc.c +++ b/examples/filelistc.c @@ -61,6 +61,7 @@ #include "../config.h" #define FULL_PROGRAM_NAME "File lister client" +#include "helpers.h" struct _remote_host { char *root_x509; @@ -281,13 +282,6 @@ static void __help_print(FILE *fso, const char *fmtname) return; } -static void __version_print(FILE *fso) -{ - fprintf(fso, "\nFile list example client.\n"); - fprintf(fso, "Examples bundle for %s %s.\n", PACKAGE_NAME, PACKAGE_VERSION); - return; -} - int main(int argc, char **argv) { char *rootca, *cert, *host, *cmd; @@ -330,7 +324,7 @@ int main(int argc, char **argv) return 0; break; case 'v': - __version_print(stdout); + version_print(stdout); return 0; break; case 'r': diff --git a/examples/helpers.h b/examples/helpers.h index 9a72c5e..9f40902 100644 --- a/examples/helpers.h +++ b/examples/helpers.h @@ -1,7 +1,6 @@ /* * Secure X Message Passing Library v2 examples. * - * (c) Originally written by somebody else ... * (c) Alexander Vdolainen 2013-2015 * * libsxmp is free software: you can redistribute it and/or modify it @@ -28,4 +27,13 @@ char *nodehostname(void); int normalize_path(char *path); +#ifdef FULL_PROGRAM_NAME +static inline void version_print(FILE *fso) +{ + fprintf(fso, "\n%s.\n", FULL_PROGRAM_NAME); + fprintf(fso, "Examples bundle for %s %s.\n", PACKAGE_NAME, PACKAGE_VERSION); + return; +} +#endif + #endif /* __SXMP_EXAMPLES_HELPERS_H__ */ diff --git a/examples/smpfd.c b/examples/smpfd.c index b4a88bc..7e08162 100644 --- a/examples/smpfd.c +++ b/examples/smpfd.c @@ -59,12 +59,12 @@ #include #include -#include "helpers.h" #include "smpf.h" #include "smpfd_defs.h" #include "../config.h" #define FULL_PROGRAM_NAME "SMPF (secure message passing file) daemon" +#include "helpers.h" static struct smpfd_ctx daemon_ctx; @@ -155,13 +155,6 @@ static void __help_print(FILE *fso, const char *fmtname) return; } -static void __version_print(FILE *fso) -{ - fprintf(fso, "\n%s.\n", FULL_PROGRAM_NAME); - fprintf(fso, "Examples bundle for %s %s.\n", PACKAGE_NAME, PACKAGE_VERSION); - return; -} - /* control operations */ static int __setcwd(void *m, sexp_t *sx) { @@ -375,7 +368,7 @@ int main(int argc, char **argv) return 0; break; case 'v': - __version_print(stdout); + version_print(stdout); return 0; break; case 'r': diff --git a/examples/streamflc.c b/examples/streamflc.c index 52ac4d6..7930bdb 100644 --- a/examples/streamflc.c +++ b/examples/streamflc.c @@ -62,6 +62,7 @@ #include "../config.h" #define FULL_PROGRAM_NAME "File lister client (builtin streams based)" +#include "helpers.h" struct _remote_host { char *root_x509; @@ -174,13 +175,6 @@ static int __remote_host_connect(struct _remote_host *rh) } /* standard output helpers */ -static void __version_print(FILE *fso) -{ - fprintf(fso, "\nFile list example client based on builtin streams.\n"); - fprintf(fso, "Examples bundle for %s %s.\n", PACKAGE_NAME, PACKAGE_VERSION); - return; -} - static void __help_print(FILE *fso, const char *fmtname) { int i; @@ -305,7 +299,7 @@ int main(int argc, char **argv) return 0; break; case 'v': - __version_print(stdout); + version_print(stdout); return 0; break; case 'r': diff --git a/examples/streamfld.c b/examples/streamfld.c index d55eb04..3402704 100644 --- a/examples/streamfld.c +++ b/examples/streamfld.c @@ -65,10 +65,10 @@ #include #include "filelist.h" -#include "helpers.h" #include "../config.h" #define FULL_PROGRAM_NAME "File lister master (builtin streams based)" +#include "helpers.h" /* firstly we need to take an rpc calls data, * sxmp uses usrtc from libtdata to store it @@ -254,13 +254,6 @@ static void __help_print(FILE *fso, const char *fmtname) return; } -static void __version_print(FILE *fso) -{ - fprintf(fso, "\nFile list example master daemon (builtin streams).\n"); - fprintf(fso, "Examples bundle for %s %s.\n", PACKAGE_NAME, PACKAGE_VERSION); - return; -} - int main(int argc, char **argv) { char *rootca = NULL, *cert = NULL; @@ -290,7 +283,7 @@ int main(int argc, char **argv) return 0; break; case 'v': - __version_print(stdout); + version_print(stdout); return 0; break; case 'r':