diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-03-15 10:26:37 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-03-15 11:14:59 +0100 |
commit | 85b043ef34186a24d960cb32417da2a610eae526 (patch) | |
tree | 1bafe274ff94b2dfc38d0fc11c42120862075221 /src/util/getopt_helpers.c | |
parent | 164eed8f5171824cf27b318afeab12f8c6ba9262 (diff) | |
download | gnunet-85b043ef34186a24d960cb32417da2a610eae526.tar.gz gnunet-85b043ef34186a24d960cb32417da2a610eae526.zip |
add GNUNET_GETOPT_OPTION_SET_ABSOLUTE_TIME
Diffstat (limited to 'src/util/getopt_helpers.c')
-rw-r--r-- | src/util/getopt_helpers.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c index 9f6f4c764..31fe093a9 100644 --- a/src/util/getopt_helpers.c +++ b/src/util/getopt_helpers.c | |||
@@ -647,6 +647,71 @@ GNUNET_GETOPT_OPTION_SET_RELATIVE_TIME (char shortName, | |||
647 | 647 | ||
648 | 648 | ||
649 | /** | 649 | /** |
650 | * Set an option of type 'struct GNUNET_TIME_Absolute' from the command line. | ||
651 | * A pointer to this function should be passed as part of the | ||
652 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options | ||
653 | * of this type. It should be followed by a pointer to a value of | ||
654 | * type 'struct GNUNET_TIME_Absolute'. | ||
655 | * | ||
656 | * @param ctx command line processing context | ||
657 | * @param scls additional closure (will point to the 'struct GNUNET_TIME_Relative') | ||
658 | * @param option name of the option | ||
659 | * @param value actual value of the option as a string. | ||
660 | * @return #GNUNET_OK if parsing the value worked | ||
661 | */ | ||
662 | static int | ||
663 | set_absolute_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | ||
664 | void *scls, | ||
665 | const char *option, | ||
666 | const char *value) | ||
667 | { | ||
668 | struct GNUNET_TIME_Absolute *val = scls; | ||
669 | |||
670 | if (GNUNET_OK != | ||
671 | GNUNET_STRINGS_fancy_time_to_absolute (value, | ||
672 | val)) | ||
673 | { | ||
674 | FPRINTF (stderr, | ||
675 | _("You must pass absolute time to the `%s' option.\n"), | ||
676 | option); | ||
677 | return GNUNET_SYSERR; | ||
678 | } | ||
679 | return GNUNET_OK; | ||
680 | } | ||
681 | |||
682 | |||
683 | /** | ||
684 | * Allow user to specify a `struct GNUNET_TIME_Absolute` | ||
685 | * (using human-readable "fancy" time). | ||
686 | * | ||
687 | * @param shortName short name of the option | ||
688 | * @param name long name of the option | ||
689 | * @param argumentHelp help text for the option argument | ||
690 | * @param description long help text for the option | ||
691 | * @param[out] val set to the time specified at the command line | ||
692 | */ | ||
693 | struct GNUNET_GETOPT_CommandLineOption | ||
694 | GNUNET_GETOPT_OPTION_SET_ABSOLUTE_TIME (char shortName, | ||
695 | const char *name, | ||
696 | const char *argumentHelp, | ||
697 | const char *description, | ||
698 | struct GNUNET_TIME_Absolute *val) | ||
699 | { | ||
700 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
701 | .shortName = shortName, | ||
702 | .name = name, | ||
703 | .argumentHelp = argumentHelp, | ||
704 | .description = description, | ||
705 | .require_argument = 1, | ||
706 | .processor = &set_absolute_time, | ||
707 | .scls = (void *) val | ||
708 | }; | ||
709 | |||
710 | return clo; | ||
711 | } | ||
712 | |||
713 | |||
714 | /** | ||
650 | * Set an option of type 'unsigned int' from the command line. | 715 | * Set an option of type 'unsigned int' from the command line. |
651 | * A pointer to this function should be passed as part of the | 716 | * A pointer to this function should be passed as part of the |
652 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options | 717 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options |