1 | /* GNU SED, a batch stream editor.
|
---|
2 | Copyright (C) 2003 Free Software Foundation, Inc.
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2, or (at your option)
|
---|
7 | any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
---|
17 |
|
---|
18 | #include "sed.h"
|
---|
19 | #include <stdlib.h>
|
---|
20 |
|
---|
21 | int mb_cur_max;
|
---|
22 |
|
---|
23 | #ifdef HAVE_MBRTOWC
|
---|
24 | /* Add a byte to the multibyte character represented by the state
|
---|
25 | CUR_STAT, and answer its length if a character is completed,
|
---|
26 | or -2 if it is yet to be completed. */
|
---|
27 | int brlen (ch, cur_stat)
|
---|
28 | int ch;
|
---|
29 | mbstate_t *cur_stat;
|
---|
30 | {
|
---|
31 | char c = ch;
|
---|
32 |
|
---|
33 | /* If we use the generic brlen, then MBRLEN == mbrlen. */
|
---|
34 | int result = mbrtowc(NULL, &c, 1, cur_stat);
|
---|
35 |
|
---|
36 | /* An invalid sequence is treated like a singlebyte character. */
|
---|
37 | if (result == -1)
|
---|
38 | {
|
---|
39 | memset (cur_stat, 0, sizeof (mbstate_t));
|
---|
40 | return 1;
|
---|
41 | }
|
---|
42 |
|
---|
43 | return result;
|
---|
44 | }
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | void
|
---|
48 | initialize_mbcs ()
|
---|
49 | {
|
---|
50 | #ifdef HAVE_MBRTOWC
|
---|
51 | mb_cur_max = MB_CUR_MAX;
|
---|
52 | #else
|
---|
53 | mb_cur_max = 1;
|
---|
54 | #endif
|
---|
55 | }
|
---|
56 |
|
---|