source: trunk/src/oldsed/sed/mbcs.c@ 3610

Last change on this file since 3610 was 599, checked in by bird, 19 years ago

GNU sed 4.1.5.

File size: 1.5 KB
Line 
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
21int 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. */
27int 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
47void
48initialize_mbcs ()
49{
50#ifdef HAVE_MBRTOWC
51 mb_cur_max = MB_CUR_MAX;
52#else
53 mb_cur_max = 1;
54#endif
55}
56
Note: See TracBrowser for help on using the repository browser.