X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fmbfile.h;h=c535107efbcadbdf408a9a66c15c4c4b8440dd89;hb=744df8b1de32a5c4047aff5e9a9fa8b680ffea6f;hp=e7a19c359836bfb4c3fb5893cd09b715e254d0f7;hpb=07ca91adc3957e0066d8813468a71047b5bc1db0;p=gnulib.git diff --git a/lib/mbfile.h b/lib/mbfile.h index e7a19c359..c535107ef 100644 --- a/lib/mbfile.h +++ b/lib/mbfile.h @@ -1,10 +1,10 @@ /* Multibyte character I/O: macros for multi-byte encodings. Copyright (C) 2001, 2005 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -12,8 +12,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + along with this program. If not, see . */ /* Written by Mitsuru Chinen and Bruno Haible . */ @@ -40,9 +39,9 @@ Here are the function prototypes of the macros. - extern void mbf_init (mb_file_t mbf, FILE *stream); - extern void mbf_getc (mbf_char_t mbc, mb_file_t mbf); - extern bool mb_iseof (const mbf_char_t mbc); + extern void mbf_init (mb_file_t mbf, FILE *stream); + extern void mbf_getc (mbf_char_t mbc, mb_file_t mbf); + extern bool mb_iseof (const mbf_char_t mbc); */ #ifndef _MBFILE_H @@ -96,10 +95,10 @@ mbfile_multi_getc (struct mbchar *mbc, struct mbfile_multi *mbf) { int c = getc (mbf->fp); if (c == EOF) - { - mbf->eof_seen = true; - goto eof; - } + { + mbf->eof_seen = true; + goto eof; + } mbf->buf[0] = (unsigned char) c; mbf->bufcount++; } @@ -108,8 +107,8 @@ mbfile_multi_getc (struct mbchar *mbc, struct mbfile_multi *mbf) if (mbf->bufcount == 1 && mbsinit (&mbf->state) && is_basic (mbf->buf[0])) { /* These characters are part of the basic character set. ISO C 99 - guarantees that their wide character code is identical to their - char code. */ + guarantees that their wide character code is identical to their + char code. */ mbc->wc = mbc->buf[0] = mbf->buf[0]; mbc->wc_valid = true; mbc->ptr = &mbc->buf[0]; @@ -124,67 +123,67 @@ mbfile_multi_getc (struct mbchar *mbc, struct mbfile_multi *mbf) for (;;) { /* We don't know whether the 'mbrtowc' function updates the state when - it returns -2, - this is the ISO C 99 and glibc-2.2 behaviour - or - not - amended ANSI C, glibc-2.1 and Solaris 2.7 behaviour. We - don't have an autoconf test for this, yet. - The new behaviour would allow us to feed the bytes one by one into - mbrtowc. But the old behaviour forces us to feed all bytes since - the end of the last character into mbrtowc. Since we want to retry - with more bytes when mbrtowc returns -2, we must backup the state - before calling mbrtowc, because implementations with the new - behaviour will clobber it. */ + it returns -2, - this is the ISO C 99 and glibc-2.2 behaviour - or + not - amended ANSI C, glibc-2.1 and Solaris 2.7 behaviour. We + don't have an autoconf test for this, yet. + The new behaviour would allow us to feed the bytes one by one into + mbrtowc. But the old behaviour forces us to feed all bytes since + the end of the last character into mbrtowc. Since we want to retry + with more bytes when mbrtowc returns -2, we must backup the state + before calling mbrtowc, because implementations with the new + behaviour will clobber it. */ mbstate_t backup_state = mbf->state; bytes = mbrtowc (&mbc->wc, &mbf->buf[0], mbf->bufcount, &mbf->state); if (bytes == (size_t) -1) - { - /* An invalid multibyte sequence was encountered. */ - /* Return a single byte. */ - bytes = 1; - mbc->wc_valid = false; - break; - } + { + /* An invalid multibyte sequence was encountered. */ + /* Return a single byte. */ + bytes = 1; + mbc->wc_valid = false; + break; + } else if (bytes == (size_t) -2) - { - /* An incomplete multibyte character. */ - mbf->state = backup_state; - if (mbf->bufcount == MBCHAR_BUF_SIZE) - { - /* An overlong incomplete multibyte sequence was encountered. */ - /* Return a single byte. */ - bytes = 1; - mbc->wc_valid = false; - break; - } - else - { - /* Read one more byte and retry mbrtowc. */ - int c = getc (mbf->fp); - if (c == EOF) - { - /* An incomplete multibyte character at the end. */ - mbf->eof_seen = true; - bytes = mbf->bufcount; - mbc->wc_valid = false; - break; - } - mbf->buf[mbf->bufcount] = (unsigned char) c; - mbf->bufcount++; - } + { + /* An incomplete multibyte character. */ + mbf->state = backup_state; + if (mbf->bufcount == MBCHAR_BUF_SIZE) + { + /* An overlong incomplete multibyte sequence was encountered. */ + /* Return a single byte. */ + bytes = 1; + mbc->wc_valid = false; + break; + } + else + { + /* Read one more byte and retry mbrtowc. */ + int c = getc (mbf->fp); + if (c == EOF) + { + /* An incomplete multibyte character at the end. */ + mbf->eof_seen = true; + bytes = mbf->bufcount; + mbc->wc_valid = false; + break; + } + mbf->buf[mbf->bufcount] = (unsigned char) c; + mbf->bufcount++; + } } else - { - if (bytes == 0) - { - /* A null wide character was encountered. */ - bytes = 1; - assert (mbf->buf[0] == '\0'); - assert (mbc->wc == 0); - } - mbc->wc_valid = true; - break; - } + { + if (bytes == 0) + { + /* A null wide character was encountered. */ + bytes = 1; + assert (mbf->buf[0] == '\0'); + assert (mbc->wc == 0); + } + mbc->wc_valid = true; + break; + } } /* Return the multibyte sequence mbf->buf[0..bytes-1]. */ @@ -200,10 +199,10 @@ mbfile_multi_getc (struct mbchar *mbc, struct mbfile_multi *mbf) char *p = &mbf->buf[0]; do - { - *p = *(p + bytes); - p++; - } + { + *p = *(p + bytes); + p++; + } while (--count > 0); } return; @@ -227,11 +226,11 @@ typedef struct mbfile_multi mb_file_t; typedef mbchar_t mbf_char_t; -#define mbf_init(mbf, stream) \ - ((mbf).fp = (stream), \ - (mbf).eof_seen = false, \ - (mbf).have_pushback = false, \ - memset (&(mbf).state, '\0', sizeof (mbstate_t)), \ +#define mbf_init(mbf, stream) \ + ((mbf).fp = (stream), \ + (mbf).eof_seen = false, \ + (mbf).have_pushback = false, \ + memset (&(mbf).state, '\0', sizeof (mbstate_t)), \ (mbf).bufcount = 0) #define mbf_getc(mbc, mbf) mbfile_multi_getc (&(mbc), &(mbf))