diff options
author | ng0 <ng0@infotropique.org> | 2017-09-05 12:03:16 +0000 |
---|---|---|
committer | ng0 <ng0@infotropique.org> | 2017-09-05 12:03:16 +0000 |
commit | d4f04e4d62663a108cf3100d9168c962a95b56c3 (patch) | |
tree | 246ba4f1c4679bec562c67cbf8c7350544ec385d /doc | |
parent | 0c9ffbeba9f19c0bde8ee9c6d3bea04f8867885c (diff) | |
download | gnunet-d4f04e4d62663a108cf3100d9168c962a95b56c3.tar.gz gnunet-d4f04e4d62663a108cf3100d9168c962a95b56c3.zip |
doc: gnunet-c-tutorial: move example code to separate files.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/gnunet-c-tutorial.texi | 66 | ||||
-rw-r--r-- | doc/tutorial-examples/001.c | 29 | ||||
-rw-r--r-- | doc/tutorial-examples/002.c | 17 | ||||
-rw-r--r-- | doc/tutorial-examples/003.c | 7 |
4 files changed, 59 insertions, 60 deletions
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 | |||
579 | and then invoke the @code{run} function (with the remaining non-option arguments) | 579 | and then invoke the @code{run} function (with the remaining non-option arguments) |
580 | and a handle to the parsed configuration (and the configuration file name that was | 580 | and a handle to the parsed configuration (and the configuration file name that was |
581 | used, which is typically not needed): | 581 | used, which is typically not needed): |
582 | 582 | @example | |
583 | \lstset{language=C} | 583 | @verbatiminclude tutorial-examples/001.c |
584 | \begin{lstlisting} | ||
585 | #include <gnunet/platform.h> | ||
586 | #include <gnunet/gnunet_util_lib.h> | ||
587 | |||
588 | static int ret; | ||
589 | |||
590 | static void | ||
591 | run (void *cls, | ||
592 | char *const *args, | ||
593 | const char *cfgfile, | ||
594 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
595 | { | ||
596 | // main code here | ||
597 | ret = 0; | ||
598 | } | ||
599 | |||
600 | int | ||
601 | main (int argc, char *const *argv) | ||
602 | { | ||
603 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
604 | GNUNET_GETOPT_OPTION_END | ||
605 | }; | ||
606 | return (GNUNET_OK == | ||
607 | GNUNET_PROGRAM_run (argc, | ||
608 | argv, | ||
609 | "binary-name", | ||
610 | gettext_noop ("binary description text"), | ||
611 | options, &run, NULL)) ? ret : 1; | ||
612 | } | ||
613 | @end example | 584 | @end example |
614 | 585 | ||
615 | @subsection Handling command-line options} | 586 | @subsection Handling command-line options} |
@@ -618,25 +589,8 @@ Options can then be added easily by adding global variables and | |||
618 | expanding the {\tt options} array. For example, the following would | 589 | expanding the {\tt options} array. For example, the following would |
619 | add a string-option and a binary flag (defaulting to @code{NULL} and | 590 | add a string-option and a binary flag (defaulting to @code{NULL} and |
620 | @code{GNUNET\_NO} respectively): | 591 | @code{GNUNET\_NO} respectively): |
621 | 592 | @example | |
622 | \lstset{language=C} | 593 | @verbatiminclude tutorial-examples/002.c |
623 | \begin{lstlisting} | ||
624 | static char *string_option; | ||
625 | static int a_flag; | ||
626 | |||
627 | // ... | ||
628 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
629 | GNUNET_GETOPT_option_string ('s', "name", "SOMESTRING", | ||
630 | gettext_noop ("text describing the string_option NAME"), | ||
631 | &string_option}, | ||
632 | GNUNET_GETOPT_option_flag ('f', "flag", | ||
633 | gettext_noop ("text describing the flag option"), | ||
634 | &a_flag), | ||
635 | GNUNET_GETOPT_OPTION_END | ||
636 | }; | ||
637 | string_option = NULL; | ||
638 | a_flag = GNUNET_SYSERR; | ||
639 | // ... | ||
640 | @end example | 594 | @end example |
641 | 595 | ||
642 | Issues such as displaying some helpful text describing options using | 596 | Issues such as displaying some helpful text describing options using |
@@ -683,16 +637,8 @@ file). | |||
683 | 637 | ||
684 | Before a client library can implement the application-specific protocol | 638 | Before a client library can implement the application-specific protocol |
685 | with the service, a connection must be created: | 639 | with the service, a connection must be created: |
686 | 640 | @example | |
687 | \lstset{language=C} | 641 | @verbatiminclude tutorial-examples/003.c |
688 | \begin{lstlisting} | ||
689 | struct GNUNET_MQ_MessageHandlers handlers[] = { | ||
690 | // ... | ||
691 | GNUNET_MQ_handler_end () | ||
692 | }; | ||
693 | struct GNUNET_MQ_Handle *mq; | ||
694 | |||
695 | mq = GNUNET_CLIENT_connect (cfg, "service-name", handlers, &error_cb, NULL); | ||
696 | @end example | 642 | @end example |
697 | 643 | ||
698 | As a result a {\tt GNUNET\_MQ\_Handle} is returned | 644 | 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 @@ | |||
1 | #include <gnunet/platform.h> | ||
2 | #include <gnunet/gnunet_util_lib.h> | ||
3 | |||
4 | static int ret; | ||
5 | |||
6 | static void | ||
7 | run (void *cls, | ||
8 | char *const *args, | ||
9 | const char *cfgfile, | ||
10 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
11 | { | ||
12 | // main code here | ||
13 | ret = 0; | ||
14 | } | ||
15 | |||
16 | int | ||
17 | main (int argc, char *const *argv) | ||
18 | { | ||
19 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
20 | GNUNET_GETOPT_OPTION_END | ||
21 | }; | ||
22 | return (GNUNET_OK == | ||
23 | GNUNET_PROGRAM_run (argc, | ||
24 | argv, | ||
25 | "binary-name", | ||
26 | gettext_noop ("binary description text"), | ||
27 | options, &run, NULL)) ? ret : 1; | ||
28 | } | ||
29 | |||
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 @@ | |||
1 | static char *string_option; | ||
2 | static int a_flag; | ||
3 | |||
4 | // ... | ||
5 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
6 | GNUNET_GETOPT_option_string ('s', "name", "SOMESTRING", | ||
7 | gettext_noop ("text describing the string_option NAME"), | ||
8 | &string_option}, | ||
9 | GNUNET_GETOPT_option_flag ('f', "flag", | ||
10 | gettext_noop ("text describing the flag option"), | ||
11 | &a_flag), | ||
12 | GNUNET_GETOPT_OPTION_END | ||
13 | }; | ||
14 | string_option = NULL; | ||
15 | a_flag = GNUNET_SYSERR; | ||
16 | // ... | ||
17 | |||
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 @@ | |||
1 | struct GNUNET_MQ_MessageHandlers handlers[] = { | ||
2 | // ... | ||
3 | GNUNET_MQ_handler_end () | ||
4 | }; | ||
5 | struct GNUNET_MQ_Handle *mq; | ||
6 | |||
7 | mq = GNUNET_CLIENT_connect (cfg, "service-name", handlers, &error_cb, NULL); | ||