doc: gnunet-c-tutorial: move example code to separate files.
authorng0 <ng0@infotropique.org>
Tue, 5 Sep 2017 12:03:16 +0000 (12:03 +0000)
committerng0 <ng0@infotropique.org>
Tue, 5 Sep 2017 12:03:16 +0000 (12:03 +0000)
doc/gnunet-c-tutorial.texi
doc/tutorial-examples/001.c [new file with mode: 0644]
doc/tutorial-examples/002.c [new file with mode: 0644]
doc/tutorial-examples/003.c [new file with mode: 0644]

index ba443e67415388c554fbd99beaab272ac473e600..12348801a817f1b68246d936e9c3a9c2efe59c76 100644 (file)
@@ -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 <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}
@@ -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 (file)
index 0000000..7f6699d
--- /dev/null
@@ -0,0 +1,29 @@
+#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;
+}
+
diff --git a/doc/tutorial-examples/002.c b/doc/tutorial-examples/002.c
new file mode 100644 (file)
index 0000000..02233fd
--- /dev/null
@@ -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 (file)
index 0000000..d13681c
--- /dev/null
@@ -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);