Here is an example illustrating the use of mu_format
and
mu_format_string
:
#include <stdio.h> #include <stdlib.h> #include <mu/format.h> int main(void) { char *str; unsigned short cursor = 0; /* Format a message to standard output. */ puts("===== mu_format ====="); mu_format(stdout, &cursor, 40, 50, 4, 2, "\ This is some text. The first line will be indented 4 \ characters, while following lines will be indented 2. Lines \ will be wrapped at 40 characters, except \ reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally \ long words, which will be wrapped at 50 characters. A line \ break will appear here:\nno matter what.\n"); /* Write a similarly formatted message to a string. */ str = mu_format_string(&cursor, 40, 50, 4, 2, "This text is similarly formatted " "to the text above.\n"); /* Print the string to standard output. */ puts("===== mu_format_string ====="); fputs(str, stdout); /* We must free the string since `mu_format_string' dynamically allocates it. */ free(str); return 0; }
And here is the output:
$ ./format -| ===== mu_format ===== -| This is some text. The first line -| will be indented 4 characters, while -| following lines will be indented 2. -| Lines will be wrapped at 40 -| characters, except -| reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa- -| aaaaaaaaaally long words, which will -| be wrapped at 50 characters. A line -| break will appear here: -| no matter what. -| ===== mu_format_string ===== -| This text is similarly formatted to -| the text above.