3 Formatting Text

Mu provides several functions for formatting text. The symbols described below are declared in mu/format.h.

Variable: unsigned short mu_format_tab_stop

The formatting functions always convert TAB characters (‘\t’) to spaces. This global variable specifies the tab stop to be used by the formatting functions. You may set it directly. The default value is MU_FORMAT_TAB_STOP (see below).

Constant: MU_FORMAT_TAB_STOP

The default value for mu_format_tab_stop (see above). Equal to 8.

Function: int mu_format (FILE *stream, unsigned short *cursor, unsigned short goal, unsigned short width, unsigned short indent, unsigned short subindent, const char *format, …)

First, this function creates an internal string based on the printf-style format string, format, and a variable number of extra arguments which are processed according to ‘%’-directives in format. See (libc)Formatted Output for more information on how format and the variable arguments are processed.

After this internal string is created, it is then printed to stream, with formatting being done according to the various parameters. For a description of what these parameters do, see Controlling Formatted Output.

This function returns 0 on success, or nonzero on error, in which case errno will be set to indicate the error (see (libc)Error Reporting).

Function: char * mu_format_string (unsigned short *cursor, unsigned short goal, unsigned short width, unsigned short indent, unsigned short subindent, const char *format, …)

This function is just like mu_format (see above), except that it returns the result in a dynamically allocated string rather than printing it to a stream.

The return value is the allocated string on success, or NULL on error, in which case errno will be set to indicate the error (see (libc)Error Reporting). If this function succeeds, the returned string must be freed when you are done with it (see (libc)Freeing after Malloc).

Function: int mu_vformat (FILE *stream, unsigned short *cursor, unsigned short goal, unsigned short width, unsigned short indent, unsigned short subindent, const char *format, va_list ap)

This function is nearly identical to mu_format, except that it takes a va_list argument, ap, rather than a variable list of arguments. This is useful if you want to write a variadic function which calls mu_vformat on its arguments (see (libc)Variadic Functions).

Function: char * mu_vformat_string (unsigned short *cursor, unsigned short goal, unsigned short width, unsigned short indent, unsigned short subindent, const char *format, va_list ap)

This function is nearly identical to mu_format_string, except that it takes a va_list argument, ap, rather than a variable list of arguments. See mu_vformat above for why this may be useful.