From: ng0 Date: Tue, 5 Sep 2017 12:03:16 +0000 (+0000) Subject: doc: gnunet-c-tutorial: move example code to separate files. X-Git-Tag: gnunet-0.11.0rc0~130 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d4f04e4d62663a108cf3100d9168c962a95b56c3;p=oweals%2Fgnunet.git doc: gnunet-c-tutorial: move example code to separate files. --- diff --git a/doc/gnunet-c-tutorial.texi b/doc/gnunet-c-tutorial.texi index ba443e674..12348801a 100644 --- a/doc/gnunet-c-tutorial.texi +++ b/doc/gnunet-c-tutorial.texi @@ -579,37 +579,8 @@ function. This function will parse command-line options, setup the scheduler 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 -#include - -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} @@ -618,25 +589,8 @@ Options can then be added easily by adding global variables and 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 @@ -683,16 +637,8 @@ file). 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 diff --git a/doc/tutorial-examples/001.c b/doc/tutorial-examples/001.c new file mode 100644 index 000000000..7f6699dd2 --- /dev/null +++ b/doc/tutorial-examples/001.c @@ -0,0 +1,29 @@ +#include +#include + +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; +} + diff --git a/doc/tutorial-examples/002.c b/doc/tutorial-examples/002.c new file mode 100644 index 000000000..02233fd61 --- /dev/null +++ b/doc/tutorial-examples/002.c @@ -0,0 +1,17 @@ +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; +// ... + diff --git a/doc/tutorial-examples/003.c b/doc/tutorial-examples/003.c new file mode 100644 index 000000000..d13681ca6 --- /dev/null +++ b/doc/tutorial-examples/003.c @@ -0,0 +1,7 @@ + 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);