diff options
Diffstat (limited to 'src/util/getopt_helpers.c')
-rw-r--r-- | src/util/getopt_helpers.c | 101 |
1 files changed, 91 insertions, 10 deletions
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c index c836c9055..32cce65dd 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 | /** |
@@ -750,6 +748,13 @@ set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
750 | unsigned int *val = scls; | 748 | unsigned int *val = scls; |
751 | 749 | ||
752 | (void) ctx; | 750 | (void) ctx; |
751 | if('-' == *value) | ||
752 | { | ||
753 | FPRINTF (stderr, | ||
754 | _("Your input for the '%s' option has to be a non negative number \n"), | ||
755 | option); | ||
756 | return GNUNET_SYSERR; | ||
757 | } | ||
753 | if (1 != SSCANF (value, | 758 | if (1 != SSCANF (value, |
754 | "%u", | 759 | "%u", |
755 | val)) | 760 | val)) |
@@ -793,6 +798,82 @@ GNUNET_GETOPT_option_uint (char shortName, | |||
793 | } | 798 | } |
794 | 799 | ||
795 | 800 | ||
801 | |||
802 | /** | ||
803 | * Set an option of type 'uint16_t' from the command line. | ||
804 | * A pointer to this function should be passed as part of the | ||
805 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options | ||
806 | * of this type. It should be followed by a pointer to a value of | ||
807 | * type 'uint16_t'. | ||
808 | * | ||
809 | * @param ctx command line processing context | ||
810 | * @param scls additional closure (will point to the 'unsigned int') | ||
811 | * @param option name of the option | ||
812 | * @param value actual value of the option as a string. | ||
813 | * @return #GNUNET_OK if parsing the value worked | ||
814 | */ | ||
815 | static int | ||
816 | set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | ||
817 | void *scls, | ||
818 | const char *option, | ||
819 | const char *value) | ||
820 | { | ||
821 | uint16_t *val = scls; | ||
822 | unsigned int v; | ||
823 | |||
824 | (void) ctx; | ||
825 | if (1 != SSCANF (value, | ||
826 | "%u", | ||
827 | &v)) | ||
828 | { | ||
829 | FPRINTF (stderr, | ||
830 | _("You must pass a number to the `%s' option.\n"), | ||
831 | option); | ||
832 | return GNUNET_SYSERR; | ||
833 | } | ||
834 | if (v > UINT16_MAX) | ||
835 | { | ||
836 | FPRINTF (stderr, | ||
837 | _("You must pass a number below %u to the `%s' option.\n"), | ||
838 | (unsigned int) UINT16_MAX, | ||
839 | option); | ||
840 | return GNUNET_SYSERR; | ||
841 | } | ||
842 | *val = (uint16_t) v; | ||
843 | return GNUNET_OK; | ||
844 | } | ||
845 | |||
846 | |||
847 | /** | ||
848 | * Allow user to specify an uint16_t. | ||
849 | * | ||
850 | * @param shortName short name of the option | ||
851 | * @param name long name of the option | ||
852 | * @param argumentHelp help text for the option argument | ||
853 | * @param description long help text for the option | ||
854 | * @param[out] val set to the value specified at the command line | ||
855 | */ | ||
856 | struct GNUNET_GETOPT_CommandLineOption | ||
857 | GNUNET_GETOPT_option_uint16 (char shortName, | ||
858 | const char *name, | ||
859 | const char *argumentHelp, | ||
860 | const char *description, | ||
861 | uint16_t *val) | ||
862 | { | ||
863 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
864 | .shortName = shortName, | ||
865 | .name = name, | ||
866 | .argumentHelp = argumentHelp, | ||
867 | .description = description, | ||
868 | .require_argument = 1, | ||
869 | .processor = &set_uint16, | ||
870 | .scls = (void *) val | ||
871 | }; | ||
872 | |||
873 | return clo; | ||
874 | } | ||
875 | |||
876 | |||
796 | /** | 877 | /** |
797 | * Closure for #set_base32(). | 878 | * Closure for #set_base32(). |
798 | */ | 879 | */ |