Difference between revisions of "Inline-comment"

From Mailutils
Jump to navigationJump to search
(Initial revision)
 
Line 7: Line 7:
 
=== Decode mode ===
 
=== Decode mode ===
  
In encode mode, the filter removes all lines beginning with a ''comment sequence'' from the input.  The default comment sequence is <tt>;</tt> (a semicolon).  The initialization of the <tt>inline-stream</tt> in this default mode is shown in the following example:
+
In decode mode, the filter removes all lines beginning with a ''comment sequence'' from the input.  The default comment sequence is <tt>;</tt> (a semicolon).  The initialization of the <tt>inline-stream</tt> in this default mode is shown in the following example:
  
 
<source lang="C">
 
<source lang="C">
Line 27: Line 27:
  
 
   initialize_input_stream (&stream);
 
   initialize_input_stream (&stream);
   rc = mu_filter_stream_create_args (&flt, input, "inline-comment", MU_FILTER_DECODE, MU_STREAM_READ, 2, argv);
+
   rc = mu_filter_create_args (&flt, input, "inline-comment", 2, argv, MU_FILTER_DECODE, MU_STREAM_READ);
 
</source>
 
</source>
  
Line 47: Line 47:
  
 
   initialize_input_stream (&stream);
 
   initialize_input_stream (&stream);
   rc = mu_filter_stream_create_args (&flt, input, "inline-comment", MU_FILTER_DECODE, MU_STREAM_READ, 3, argv);
+
   rc = mu_filter_create_args (&flt, input, "inline-comment", 3, argv, MU_FILTER_DECODE, MU_STREAM_READ);
 
</source>
 
</source>
  

Revision as of 07:13, 25 August 2011

Introduction

The inline-comment filter in decode mode removes inline comments from the input stream.

In encode mode it outputs a given byte sequence at the beginning of each output line.

Decode mode

In decode mode, the filter removes all lines beginning with a comment sequence from the input. The default comment sequence is ; (a semicolon). The initialization of the inline-stream in this default mode is shown in the following example:

  int rc;          /* Return code */
  mu_stream_t flt; /* Filter stream */
  mu_stream_t input; /* Input stream */

  initialize_input_stream (&stream);
  rc = mu_filter_stream_create (&flt, input, "inline-comment", MU_FILTER_DECODE, MU_STREAM_READ);

To change the comment sequence supply the new sequence as the first argument. For example, the following filter will remove any lines starting with a rem:

  int rc;          /* Return code */
  mu_stream_t flt; /* Filter stream */
  mu_stream_t input; /* Input stream */
  char *argv[] = { "inline-comment", "rem", NULL },

  initialize_input_stream (&stream);
  rc = mu_filter_create_args (&flt, input, "inline-comment", 2, argv, MU_FILTER_DECODE, MU_STREAM_READ);

Notice that the above filter will remove any line starting with the rem characters, for example:

rem A comment.
remark that should not be removed.

Removing of the second line seems wrong in most cases, therefore the filter supports a special whitespace-must-follow mode, in which it recognizes the comment sequence only when it is immediatly followed by a whitespace character. This mode is enabled by the -S option to the filter. E.g.:

  int rc;          /* Return code */
  mu_stream_t flt; /* Filter stream */
  mu_stream_t input; /* Input stream */
  char *argv[] = { "inline-comment", "rem", "-S", NULL },

  initialize_input_stream (&stream);
  rc = mu_filter_create_args (&flt, input, "inline-comment", 3, argv, MU_FILTER_DECODE, MU_STREAM_READ);

The following options modify the default behavior:

-i STR
Emit line number information after each contiguous sequence of removed lines. STR supplies "information starter" -- a sequence of characters which is output before the actual line number.
-r
Remove empty lines, i.e. the ones that contain only whitespace characters.
-s
Squeeze whitespace. Each sequence of two or more whitespace characters encountered on input is replaced by a single space character on output.
-S
A whitespace-must-follow mode. A comment sequence is recognized only if followed by a whitespace character. The character itself is retained on output.

Encode mode

In encode mode the inline-comment filter adds a comment-starter sequence at the beginning of each line. As previously, the default comment-starter is ';', which can be changed by specifying the desired comment starter as the first argument to the filter creation sequence.

The only option supported in this mode is -S, which enables the whitespace-must-follow mode, in which a single space character (ASCII 20) is output after each comment sequence.