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