File: textwrap.3

package info (click to toggle)
libtextwrap 0.1-14.2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,424 kB
  • sloc: sh: 8,186; ansic: 322; makefile: 77; perl: 38
file content (114 lines) | stat: -rw-r--r-- 4,083 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
.\" textwrap.3   -*- nroff -*-
.TH textwrap 3 "2003-08-16"
.SH NAME
textwrap \- line-folding (text-wrapping) library with i18n support
.SH SYNOPSIS
\fB#include <textwrap.h>\fR

\fBvoid textwrap_init(textwrap_t *prop);\fR
.br
\fBvoid textwrap_columns(textwrap_t *prop, int columns);\fR
.br
\fBvoid textwrap_tab(textwrap_t *prop, int tab);\fR
.br
\fBvoid textwrap_head(textwrap_t *prop, const char *head1, const char *head2);\fR
.br
\fBchar *textwrap(const textwrap_t *prop, const char *text);\fR
.\" ********************************************************************
.SH DESCRIPTION
\fBtextwrap\fR is a library to wrap given text to fit the terminal with
a certain width.  This is like \fBText::Wrap\fR(3pm).
.P
Unlike other libraries or functions, this supports internationalization.
.P
At first, this automatically detects the \fBcurrent LC_CTYPE locale\fR
and follows it.
To enable this, your application must call \fBsetlocale\fR(3) in advance.
.P
Next, this supports \fBmultibyte encodings\fR such as UTF-8 and EUC-JP.
In multibyte encodings, one character consists from one or more bytes.
.P
Third, this supports \fBfullwidth characters\fR such as CJK Ideogram,
Katakana, Hiragana, and Hangul.  These characters occupy two columns
per one character on the terminal.
.P
Forth, this supports \fBcombining characters\fR such as Thai and accents
for Latin scripts.  These characters occupy zero columns per one character
on the terminal.
.P
Fifth, this supports languages which do not use whitespaces between
words.  In these languages, lines can be folded at any places with
small amount of exception (such as before commas).
.\" ********************************************************************
.SH USAGE
At first, you will have to prepare a set of parameters as \fItextwrap_t\fR.
Prepare a variable of \fItextwrap_t\fR and then call \fBtextwrap_init()\fR
with the pointer to the variable.
.P
Members of \fItextwrap_t\fR may change in future.  Thus, please use
API functions to modify values of these members.
.TP
\fBtextwrap_columns()\fR
Specifies the number of columns or width of your terminal.
The result string will not have longer line than this value.
The default value is 76.
.TP
\fBtextwrap_tab()\fR
Specifies the number of columns for TAB code.
The default is 8.
.TP
\fBtextwrap_head()\fR
Specifies strings which will be added at the top of the top line
and following lines.  The defaults are NULL for \fBhead1\fR and
NULL for \fBhead2\fR.
.P
The real text-wrapping is performed by \fBtextwrap()\fR.
The text to be folded is given as \fItext\fR.  The text must be encoded
in the current LC_CTYPE locale, i.e., ISO-8859-1 in ISO-8859-1 locales,
KOI8-R in KOI8-R locales, EUC-JP in EUC-JP locales, UTF-8 in UTF-8
locales, and so on.  
Though you might not be very familiar with the term LC_CTYPE locale,
this behavior is under what most of users use UNIX-like systems.  Thus,
you do not have to convert the encoding
of the string.
.P
The \fItext\fR can contain tab code (0x09).  The tab is converted into
proper number of space code (0x20) by \fBtextwrap\fR.
.\" ********************************************************************
.SH RETURN VALUE
\fBtextwrap()\fR returns the line-folded text.
You can free(3) the given value.

In case of any error while processing the string, the text <ERR> will be
appended to the output and processing will be aborted.
.\" ********************************************************************
.SH EXAMPLE
.nf
#include <stdio.h>
#include <textwrap.h>

main()
{
    textwrap_t property;
    char *text = "This is a sample.\\n";
    char *outtext;

    textwrap_init(&property);
    textwrap_columns(&property, 70);
    outtext = textwrap(&property, text);
    printf("%s\\n",outtext);
    free(outtext);
}
.fi
.\" ********************************************************************
.SH SEE ALSO
Manual pages of
\fBdotextwrap\fR(1),
\fBsetlocale\fR(3),
\fBlocale\fR(7),
\fBcharsets\fR(7), and
\fBUTF-8\fR(7).
.\" ********************************************************************
.SH AUTHOR
Tomohiro KUBOTA <kubota@debian.org>.