No Clock  1.0.2
Pretty Printing Indentation

Display pretty indentation. More...

Enumerations

enum  pp_indent_style { INDENT_SPACES, INDENT_TABS, INDENT_UNKNOWN }
 Indentation styles. More...
 

Functions

void pretty_print_indent_decrease (void)
 Decrease the indentation level. More...
 
void pretty_print_indent_fprint (FILE *f)
 Indent the current line of a stream. More...
 
static size_t pretty_print_indent_get_level (void)
 Get the current indentation level. More...
 
static pp_indent_style pretty_print_indent_get_style (void)
 Get the current indentation style. More...
 
static const char * pretty_print_indent_get_style_string (pp_indent_style style)
 Get the string corresponding to an indent style. More...
 
void pretty_print_indent_increase (void)
 Increase the indentation level. More...
 
size_t pretty_print_indent_level (void)
 Get the current indentation level. More...
 
void pretty_print_indent_set_style (pp_indent_style style)
 Set the indentation style. More...
 
pp_indent_style pretty_print_indent_style (void)
 Get the current indentation style. More...
 
const char * pretty_print_indent_style_string (pp_indent_style style)
 Get the string corresponding to an indent style. More...
 
char * pretty_print_indent_to_string (void)
 Get a string that represents the current level of indentation. More...
 

Detailed Description

Display pretty indentation.

Since
version 1.0.0

Indentation level

The current indentation level can be inspected using pretty_print_indent_level(). It can be increased or decreased with pretty_print_indent_increase() and pretty_print_indent_decrease().

Indentation style

The current implementation provides two indentation styles:

The currently used indentation style can be inspected using pretty_print_indent_style(). It can be changed using pretty_print_indent_set_style().

The string representation of a given indentation style can be obtained using pretty_print_indent_style_string(). However, the current implementation does not allow the user to change the string representation of an indentation style...

Usage

One can either directly print the indentation into a stream with pretty_print_indent_fprint() or convert it into a string using pretty_print_indent_to_string().

Please note that the string returned by pretty_print_indent_to_string() is malloc'd and should be free'd once it is useless.

Example

fprintf (stdout, "while (i < 100) {\n");
fprintf (stdout, "++i;\n");
fprintf (stdout, "}\n");

Enumeration Type Documentation

#include <include/noclock/pretty_print.h>

Indentation styles.

Since
version 1.0.0
Enumerator
INDENT_SPACES 

Indent with spaces.

INDENT_TABS 

Indent with tabs.

INDENT_UNKNOWN 

Unknown indent style.

Function Documentation

void pretty_print_indent_decrease ( void  )

#include <include/noclock/pretty_print.h>

Decrease the indentation level.

Since
version 1.0.0
void pretty_print_indent_fprint ( FILE *  f)

#include <include/noclock/pretty_print.h>

Indent the current line of a stream.

Since
version 1.0.0
Parameters
fStream.
Precondition
The line of the stream should be empty for proper indentation.
Note
If the indentation style is set to INDENT_UNKNOWN, the current implementation defaults to INDENT_SPACES. This behaviour may be subject to change.
static size_t pretty_print_indent_get_level ( void  )
inlinestatic

#include <include/noclock/pretty_print.h>

Get the current indentation level.

Deprecated:
Please use pretty_print_indent_level().
Since
version 1.0.0
Returns
The current indentation level.
Note
This is equivalent to:
See also
pretty_print_indent_level()
static pp_indent_style pretty_print_indent_get_style ( void  )
inlinestatic

#include <include/noclock/pretty_print.h>

Get the current indentation style.

Deprecated:
Please use pretty_print_indent_style().
Since
version 1.0.0
Return values
INDENT_SPACESif the current indentation style is set to spaces.
INDENT_TABSif the current indentation style is set to tabs.
INDENT_UNKNOWNif the current indentation style is unknown.
Note
This is equivalent to:
See also
pretty_print_indent_style()
static const char* pretty_print_indent_get_style_string ( pp_indent_style  style)
inlinestatic

#include <include/noclock/pretty_print.h>

Get the string corresponding to an indent style.

Deprecated:
Plase use pretty_print_indent_style_string().
Since
version 1.0.0
Parameters
styleThe style.
Returns
Corresponding string.
Note
This is equivalent to:
See also
pretty_print_indent_style_string()
void pretty_print_indent_increase ( void  )

#include <include/noclock/pretty_print.h>

Increase the indentation level.

Since
version 1.0.0
size_t pretty_print_indent_level ( void  )

#include <include/noclock/pretty_print.h>

Get the current indentation level.

Since
version 1.0.0
Returns
The current indentation level.
void pretty_print_indent_set_style ( pp_indent_style  style)

#include <include/noclock/pretty_print.h>

Set the indentation style.

Since
version 1.0.0
Parameters
styleThe desired indentation style.
pp_indent_style pretty_print_indent_style ( void  )

#include <include/noclock/pretty_print.h>

Get the current indentation style.

Since
version 1.0.0
Return values
INDENT_SPACESif the current indentation style is set to spaces.
INDENT_TABSif the current indentation style is set to tabs.
INDENT_UNKNOWNif the current indentation style is unknown.
const char* pretty_print_indent_style_string ( pp_indent_style  style)

#include <include/noclock/pretty_print.h>

Get the string corresponding to an indent style.

Since
version 1.0.0
Parameters
styleThe style.
Returns
Corresponding string.
char* pretty_print_indent_to_string ( void  )

#include <include/noclock/pretty_print.h>

Get a string that represents the current level of indentation.

Since
version 1.0.0
Returns
A string of indentation.
Warning
The resulting string is malloc'd. It is up to the user to free it.
Note
If the indentation style is set to INDENT_UNKNOWN, the current implementation defaults to INDENT_SPACES. This behaviour may be subject to change.