and then invoke the @code{run} function (with the remaining non-option arguments)
and a handle to the parsed configuration (and the configuration file name that was
used, which is typically not needed):
-
-\lstset{language=C}
-\begin{lstlisting}
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_util_lib.h>
-
-static int ret;
-
-static void
-run (void *cls,
- char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- // main code here
- ret = 0;
-}
-
-int
-main (int argc, char *const *argv)
-{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
- return (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc,
- argv,
- "binary-name",
- gettext_noop ("binary description text"),
- options, &run, NULL)) ? ret : 1;
-}
+@example
+@verbatiminclude tutorial-examples/001.c
@end example
@subsection Handling command-line options}
expanding the {\tt options} array. For example, the following would
add a string-option and a binary flag (defaulting to @code{NULL} and
@code{GNUNET\_NO} respectively):
-
-\lstset{language=C}
-\begin{lstlisting}
-static char *string_option;
-static int a_flag;
-
-// ...
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_string ('s', "name", "SOMESTRING",
- gettext_noop ("text describing the string_option NAME"),
- &string_option},
- GNUNET_GETOPT_option_flag ('f', "flag",
- gettext_noop ("text describing the flag option"),
- &a_flag),
- GNUNET_GETOPT_OPTION_END
- };
- string_option = NULL;
- a_flag = GNUNET_SYSERR;
-// ...
+@example
+@verbatiminclude tutorial-examples/002.c
@end example
Issues such as displaying some helpful text describing options using
Before a client library can implement the application-specific protocol
with the service, a connection must be created:
-
-\lstset{language=C}
-\begin{lstlisting}
- struct GNUNET_MQ_MessageHandlers handlers[] = {
- // ...
- GNUNET_MQ_handler_end ()
- };
- struct GNUNET_MQ_Handle *mq;
-
- mq = GNUNET_CLIENT_connect (cfg, "service-name", handlers, &error_cb, NULL);
+@example
+@verbatiminclude tutorial-examples/003.c
@end example
As a result a {\tt GNUNET\_MQ\_Handle} is returned
--- /dev/null
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_util_lib.h>
+
+static int ret;
+
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ // main code here
+ ret = 0;
+}
+
+int
+main (int argc, char *const *argv)
+{
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ return (GNUNET_OK ==
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "binary-name",
+ gettext_noop ("binary description text"),
+ options, &run, NULL)) ? ret : 1;
+}
+
--- /dev/null
+static char *string_option;
+static int a_flag;
+
+// ...
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_string ('s', "name", "SOMESTRING",
+ gettext_noop ("text describing the string_option NAME"),
+ &string_option},
+ GNUNET_GETOPT_option_flag ('f', "flag",
+ gettext_noop ("text describing the flag option"),
+ &a_flag),
+ GNUNET_GETOPT_OPTION_END
+ };
+ string_option = NULL;
+ a_flag = GNUNET_SYSERR;
+// ...
+