1.7. Source Code

1.7.1. Inline Python

This is how we write in reStructuredText

.. code-block:: python
   :emphasize-lines: 2,4

   def myEntryPoint(myParam):
        # validate myParam
        print ("Processing myParam")
        # log the output

The reStructuredText text shown above is represented as shown below...

def myEntryPoint(myParam):
     # validate myParam
     print ("Processing myParam")
     # log the output

1.7.2. Inline C

This is how we write in reStructuredText

.. code-block:: c
   :emphasize-lines: 3

   int myEntryPoint(int myParam) {
        int retVal;
        /* validate myParam */
        printf("Processing myParam");
        retVal = process_theParam(myParam);
        /* log the output */
        return retVal;
   }

The reStructuredText text shown above is represented as shown below...

int myEntryPoint(int myParam) {
     int retVal;
     /* validate myParam */
     printf("Processing myParam");
     retVal = process_theParam(myParam);
     /* log the output */
     return retVal;
}

1.7.3. Include external Python Script

This is how we write in reStructuredText

.. literalinclude:: source-code.sample.py.txt
    :language: python

The reStructuredText text shown above is represented as shown below...

def myEntryPoint(myParam):
    # validate myParam
    print ("Processing myParam")
    # log the output

1.7.4. Include external C Code

This is how we write in reStructuredText

.. literalinclude:: source-code.sample.c.txt
   :language: c
   :linenos:

The reStructuredText text shown above is represented as shown below...

1
2
3
4
5
6
7
8
int myEntryPoint(int myParam) {
    int retVal;
    /* validate myParam */
    printf("Processing myParam");
    retVal = process_theParam(myParam);
    /* log the output */
    return retVal;
}

See more at