aboutsummaryrefslogtreecommitdiff
path: root/src/util/getopt_helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/getopt_helpers.c')
-rw-r--r--src/util/getopt_helpers.c94
1 files changed, 84 insertions, 10 deletions
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c
index c836c9055..c55b22fb6 100644
--- a/src/util/getopt_helpers.c
+++ b/src/util/getopt_helpers.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2006, 2011 GNUnet e.V. 3 Copyright (C) 2006, 2011 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software: you can redistribute it and/or modify it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20 18
21/** 19/**
@@ -793,6 +791,82 @@ GNUNET_GETOPT_option_uint (char shortName,
793} 791}
794 792
795 793
794
795/**
796 * Set an option of type 'uint16_t' from the command line.
797 * A pointer to this function should be passed as part of the
798 * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options
799 * of this type. It should be followed by a pointer to a value of
800 * type 'uint16_t'.
801 *
802 * @param ctx command line processing context
803 * @param scls additional closure (will point to the 'unsigned int')
804 * @param option name of the option
805 * @param value actual value of the option as a string.
806 * @return #GNUNET_OK if parsing the value worked
807 */
808static int
809set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
810 void *scls,
811 const char *option,
812 const char *value)
813{
814 uint16_t *val = scls;
815 unsigned int v;
816
817 (void) ctx;
818 if (1 != SSCANF (value,
819 "%u",
820 &v))
821 {
822 FPRINTF (stderr,
823 _("You must pass a number to the `%s' option.\n"),
824 option);
825 return GNUNET_SYSERR;
826 }
827 if (v > UINT16_MAX)
828 {
829 FPRINTF (stderr,
830 _("You must pass a number below %u to the `%s' option.\n"),
831 (unsigned int) UINT16_MAX,
832 option);
833 return GNUNET_SYSERR;
834 }
835 *val = (uint16_t) v;
836 return GNUNET_OK;
837}
838
839
840/**
841 * Allow user to specify an uint16_t.
842 *
843 * @param shortName short name of the option
844 * @param name long name of the option
845 * @param argumentHelp help text for the option argument
846 * @param description long help text for the option
847 * @param[out] val set to the value specified at the command line
848 */
849struct GNUNET_GETOPT_CommandLineOption
850GNUNET_GETOPT_option_uint16 (char shortName,
851 const char *name,
852 const char *argumentHelp,
853 const char *description,
854 uint16_t *val)
855{
856 struct GNUNET_GETOPT_CommandLineOption clo = {
857 .shortName = shortName,
858 .name = name,
859 .argumentHelp = argumentHelp,
860 .description = description,
861 .require_argument = 1,
862 .processor = &set_uint16,
863 .scls = (void *) val
864 };
865
866 return clo;
867}
868
869
796/** 870/**
797 * Closure for #set_base32(). 871 * Closure for #set_base32().
798 */ 872 */