Prev Next srcfile

Displaying Source Code From a File

Syntax
     srcfile
     srcthisfile
See Also
Optional
Purpose
Letter Case
Delimiter Sequence
filename
     srcfile
     srcthisfile
indent
     Example
start
     escape
stop
     escape
     Example
skip
Tab Stops

Syntax

srcfile
$srcfile%filename%$$
$srcfile%filename%indent%$$
$srcfile%filename%indent%start%stop%$$
$srcfile%filename%indent%start%stop%skip$$

srcthisfile
$srcthisfile%indent%$$
$srcthisfile%indent%start%stop%$$
$srcthisfile%indent%start%stop%skip$$

See Also
getting started , srccode , codep , verbatim

Optional
These commands are optional and only supported when the source_highlight library are successfully found; see the output printed by the cmake command .

Purpose
These commands will display the specified input file as program source code with highlighting.

Letter Case
Upper case letters versus lower case letters does not matter when determining the language corresponding to the file extension. For example, the R programming language would correspond to filename equal to my_file.R or my_file.r.

Delimiter Sequence
     %filename%indent%start%stop%skip%$$
is a delimiter sequence where % can be any character that is not a letter.

filename

srcfile
The value of filename specifies the name of the file that is displayed. Leading and trailing white space in filename is ignored. The filename must have a file extension . The file extension, without the period '.', is used to determine the source code language.

srcthisfile
The $srcthisfile command uses the input file, where the command occurs, for filename .

indent
If indent is present, it is a positive integer and specifies the number of spaces to indent the output. (It is best if the indent is a multiple of the tabsize .)

Example
The following command
 
     $tabsize 4$$
     $srcfile%src/highlight.h%4%$$
displays the entire file highlight.h, with a four space indentation as follows:
    # ifndef HIGHLIGHT_INCLUDED
    # define HIGHLIGHT_INCLUDED
    /* ----------------------------------------------------------------------------
    OMhelp: Language Independent Embedded Documentation
              Copyright (C) 1998-2019 Bradley M. Bell
    OMhelp is distributed under the terms of the
                GNU General Public License Version 2.
    ---------------------------------------------------------------------------- */
    # ifdef __cplusplus
    extern "C" {
    # endif
    
    // BEGIN PROTOTYPE
    extern char* highlight(
        const char* input_text_cstr     ,
        const char* input_lang_cstr     ,
        const char* output_lang_cstr    ,
        int         indent              ,
        int         tabsize
    );
    extern char* file_ext2lang(const char* file_ext_cstr);
    // END PROTOTYPE
    # ifdef __cplusplus
    }
    # endif
    # endif
Note that a newline was automatically added at the beginning of the file.

start
If start is present, it specifies a sequence of characters after which output should start. In this case none of the characters in the file before, and including, this starting sequence are displayed.

escape
If the escape character is present in start , there must be three decimal digits following it. In this case the escape character together with the three following characters, represent the single character with ascii code equal to the decimal value of the three decimal digits.

stop
If start is present, stop must also be present. It specifies a sequence of characters just before which output should stop. In this case none of the characters in the file following, and including, this stopping sequences are displayed.

escape
If the escape character is present in stop , there must be three decimal digits following it. In this case the escape character together with the three following characters, represent the single character with ascii code equal to the decimal value of the three decimal digits.

Example
The following command sequence
 
    $srcfile%src/highlight.h%8%// BEGIN PROTOTYPE%// END PROTOTYPE%$$
displays the following output:
        extern char* highlight(
            const char* input_text_cstr     ,
            const char* input_lang_cstr     ,
            const char* output_lang_cstr    ,
            int         indent              ,
            int         tabsize
        );
        extern char* file_ext2lang(const char* file_ext_cstr);
Note that the newline after // BEGIN PROOTYPE, and the newline before // END PROTOTYPE, are included in the output. Also note that the previous tabsize command is still in effect.


If skip is present, it is a positive integer that specifies the number of start matches to skip. This is very useful when the $srcfile command refers to the same file as the command is in. The skip option can be used to skip the match on the command and go forward to the location that you wish to display.

Tab Stops
The tabsize command enables you to match the indentation of the srcfile and srcthisfile commands with one of the tabbing columns.
Input File: omh/srcfile.omh