unconditionally compile for MBCS

2012-03-16  Paolo Bonzini  <bonzini@gnu.org>

	* sed/execute.c: Unconditionally compile for MBCS.
	* sed/mbcs.c: Unconditionally compile for MBCS.
	* sed/sed.h: Unconditionally compile for MBCS.
This commit is contained in:
Paolo Bonzini committed 2012-03-16 09:43:01 +01:00
1 parent 9ea38da9fb
commit 32d990dd60
4 files changed
+6 -73

No files matched your search

+6
View File
@@ -1,3 +1,9 @@
2012-03-16 Paolo Bonzini <bonzini@gnu.org>
* sed/execute.c: Unconditionally compile for MBCS.
* sed/mbcs.c: Unconditionally compile for MBCS.
* sed/sed.h: Unconditionally compile for MBCS.
2012-03-16 Paolo Bonzini <bonzini@gnu.org>
* basicdefs.h: Enjoy gnulib's headers.
-52
View File
@@ -55,16 +55,10 @@ struct line {
size_t length; /* Length of text (or active, if used). */
size_t alloc; /* Allocated space for active. */
bool chomped; /* Was a trailing newline dropped? */
#ifdef HAVE_MBRTOWC
mbstate_t mbstate;
#endif
};
#ifdef HAVE_MBRTOWC
#define SIZEOF_LINE offsetof (struct line, mbstate)
#else
#define SIZEOF_LINE (sizeof (struct line))
#endif
/* A queue of text to write out at the end of a cycle
(filled by the "a", "r" and "R" commands.) */
@@ -185,7 +179,6 @@ str_append(to, string, length)
MEMCPY(to->active + to->length, string, length);
to->length = new_length;
#ifdef HAVE_MBRTOWC
if (mb_cur_max > 1 && !is_utf8)
while (length)
{
@@ -206,7 +199,6 @@ str_append(to, string, length)
else
break;
}
#endif
}
static void str_append_modified P_((struct line *, const char *, size_t,
@@ -218,7 +210,6 @@ str_append_modified(to, string, length, type)
size_t length;
enum replacement_types type;
{
#ifdef HAVE_MBRTOWC
mbstate_t from_stat;
if (type == REPL_ASIS)
@@ -284,39 +275,6 @@ str_append_modified(to, string, length, type)
abort ();
}
}
#else
size_t old_length = to->length;
char *start, *end;
str_append(to, string, length);
start = to->active + old_length;
end = start + length;
/* Now do the required modifications. First \[lu]... */
if (type & REPL_UPPERCASE_FIRST)
{
*start = toupper(*start);
start++;
type &= ~REPL_UPPERCASE_FIRST;
}
else if (type & REPL_LOWERCASE_FIRST)
{
*start = tolower(*start);
start++;
type &= ~REPL_LOWERCASE_FIRST;
}
if (type == REPL_ASIS)
return;
/* ...and then \[LU] */
if (type == REPL_UPPERCASE)
for (; start != end; start++)
*start = toupper(*start);
else
for (; start != end; start++)
*start = tolower(*start);
#endif
}
/* Initialize a "struct line" buffer. Copy multibyte state from `state'
@@ -334,12 +292,10 @@ line_init(buf, state, initial_size)
buf->length = 0;
buf->chomped = true;
#ifdef HAVE_MBRTOWC
if (state)
memcpy (&buf->mbstate, &state->mbstate, sizeof (buf->mbstate));
else
memset (&buf->mbstate, 0, sizeof (buf->mbstate));
#endif
}
/* Reset a "struct line" buffer to length zero. Copy multibyte state from
@@ -354,12 +310,10 @@ line_reset(buf, state)
else
{
buf->length = 0;
#ifdef HAVE_MBRTOWC
if (state)
memcpy (&buf->mbstate, &state->mbstate, sizeof (buf->mbstate));
else
memset (&buf->mbstate, 0, sizeof (buf->mbstate));
#endif
}
}
@@ -394,10 +348,8 @@ line_copy(from, to, state)
to->chomped = from->chomped;
MEMCPY(to->active, from->active, from->length);
#ifdef HAVE_MBRTOWC
if (state)
MEMCPY(&to->mbstate, &from->mbstate, sizeof (from->mbstate));
#endif
}
/* Append the contents of the line `from' to the line `to'.
@@ -413,10 +365,8 @@ line_append(from, to, state)
str_append(to, from->active, from->length);
to->chomped = from->chomped;
#ifdef HAVE_MBRTOWC
if (state)
MEMCPY (&to->mbstate, &from->mbstate, sizeof (from->mbstate));
#endif
}
/* Exchange two "struct line" buffers.
@@ -1602,7 +1552,6 @@ execute_program(vec, input)
case 'y':
{
#ifdef HAVE_MBRTOWC
if (mb_cur_max > 1)
{
int idx, prev_idx; /* index in the input line. */
@@ -1670,7 +1619,6 @@ execute_program(vec, input)
}
}
else
#endif /* HAVE_MBRTOWC */
{
unsigned char *p, *e;
p = CAST(unsigned char *)line.active;
-6
View File
@@ -24,7 +24,6 @@
int mb_cur_max;
bool is_utf8;
#ifdef HAVE_MBRTOWC
/* Add a byte to the multibyte character represented by the state
CUR_STAT, and answer its length if a character is completed,
or -2 if it is yet to be completed. */
@@ -46,7 +45,6 @@ int brlen (ch, cur_stat)
return result;
}
#endif
void
initialize_mbcs ()
@@ -57,10 +55,6 @@ initialize_mbcs ()
codeset_name = locale_charset ();
is_utf8 = (strcmp (codeset_name, "UTF-8") == 0);
#ifdef HAVE_MBRTOWC
mb_cur_max = MB_CUR_MAX;
#else
mb_cur_max = 1;
#endif
}
-15
View File
@@ -241,8 +241,6 @@ extern bool use_extended_syntax_p;
extern int mb_cur_max;
extern bool is_utf8;
#ifdef HAVE_MBRTOWC
#ifdef HAVE_BTOWC
#define MBRTOWC(pwc, s, n, ps) \
(mb_cur_max == 1 ? \
(*(pwc) = btowc (*(unsigned char *) (s)), 1) : \
@@ -252,13 +250,6 @@ extern bool is_utf8;
(mb_cur_max == 1 ? \
(*(s) = wctob ((wint_t) (wc)), 1) : \
wcrtomb ((s), (wc), (ps)))
#else
#define MBRTOWC(pwc, s, n, ps) \
mbrtowc ((pwc), (s), (n), (ps))
#define WCRTOMB(s, wc, ps) \
wcrtomb ((s), (wc), (ps))
#endif
#define MBSINIT(s) \
(mb_cur_max == 1 ? 1 : mbsinit ((s)))
@@ -269,12 +260,6 @@ extern bool is_utf8;
#define BRLEN(ch, ps) \
(mb_cur_max == 1 ? 1 : brlen (ch, ps))
#else
#define MBSINIT(s) 1
#define MBRLEN(s, n, ps) 1
#define BRLEN(ch, ps) 1
#endif
extern int brlen P_ ((int ch, mbstate_t *ps));
extern void initialize_mbcs P_ ((void));