@example tag

This tag inserts a piece of code from source code file in the document. The code may be put in a frame with colored syntax depending on output format.

It is possible to select some code file parts by adding anchor comments in the source file ( /* anchor name */ on a single line) and specifying an anchor name pattern. All lines following a matching anchor line will be retained and other lines will be ignored. A /* ... */ comment or /* ... name */ comment in ignored file part will insert an ellipsis line.

Flags available for the @code tag can be used. Moreover, the P flag can be used to insert a code comment with path to the example file in inline code block. This behavior may be enforced for all examples by using the show_examples_path option.

See also code_path section and @scope tag section.

Syntax  

@example <path to source file>[:<label>] [<flags>] [{<scope>}] <end of line>

Examples  

Consider the following C source file:

/*
Long license header
*/

/* anchor global */

#include <stdio.h>

FILE *file;

int main()
{
/* anchor open */
file = fopen("foo,h", "rw");
if (file == NULL)
return 1;

/* anchor write */
fputs("test", file);
/* ... */
/* anchor close */

fclose(file);
/* anchor global */
return 0;
}

To insert the whole file with line numbers:

@example path/to/file.c N

If you want to skip the header:

@example path/to/file.c:global|open|write|close

If you just want to show how to open and close a file:

@example path/to/file.c:open|close

This will result in the following code being inserted:

file = fopen("foo,h", "rw");
if (file == NULL)
return 1;


[ ... ]


fclose(file);

Valid XHTML 1.0 StrictGenerated by diaxen on Sun Jan 8 22:43:00 2012 using MkDoc