Difference between revisions of "C-escape"

From Mailutils
Jump to navigationJump to search
m
 
Line 11: Line 11:
 
The following object, declared in mailutils/filter.h describes the ''C-escape'' filter:
 
The following object, declared in mailutils/filter.h describes the ''C-escape'' filter:
  
<source lang="C">
+
<syntaxhighlight lang="C">
 
extern mu_filter_record_t mu_c_escape_filter;
 
extern mu_filter_record_t mu_c_escape_filter;
</source>
+
</syntaxhighlight>
  
 
The example below shows how to create an instance of this filter in decode mode for reading:
 
The example below shows how to create an instance of this filter in decode mode for reading:
  
<source lang="C">
+
<syntaxhighlight lang="C">
 
   int rc;          /* Return code */
 
   int rc;          /* Return code */
 
   mu_stream_t flt; /* Filter stream */
 
   mu_stream_t flt; /* Filter stream */
Line 24: Line 24:
 
   initialize_input_stream (&input);
 
   initialize_input_stream (&input);
 
   rc = mu_filter_create (&flt, input, "C-escape", MU_FILTER_DECODE, MU_STREAM_READ);
 
   rc = mu_filter_create (&flt, input, "C-escape", MU_FILTER_DECODE, MU_STREAM_READ);
</source>
+
</syntaxhighlight>
  
 
[[Category:Filters]]
 
[[Category:Filters]]
 
[[Category:C API]]
 
[[Category:C API]]

Latest revision as of 13:21, 16 October 2023

The C-escape filter replaces C escape sequences with the corresponding control character and vice versa.

In encode mode, recognized control characters are replaced with their C escapes. For example, newline (ASCII 10) becomes \n, horizontal tab (ASCII 9) becomes \t, etc.

In decode mode, the reverse operation is performed, i.e. each C escape is replaced with the corresponding character. Unrecognized escape sequences are copied verbatim.

Only named escapes are supported, i.e.: \\, \a, \b, \f, \n, \r, \t, \v.

This filter does not take arguments.

The following object, declared in mailutils/filter.h describes the C-escape filter:

extern mu_filter_record_t mu_c_escape_filter;

The example below shows how to create an instance of this filter in decode mode for reading:

  int rc;          /* Return code */
  mu_stream_t flt; /* Filter stream */
  mu_stream_t input; /* Input stream */
 
  initialize_input_stream (&input);
  rc = mu_filter_create (&flt, input, "C-escape", MU_FILTER_DECODE, MU_STREAM_READ);