euc.c revision 4297a3b0d0a35d80f86fff155e288e885a100e6d
/*
* Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Paul Borman at Krystal Technologies.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Copyright 2010 Nexenta Systems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include "lint.h"
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include "runetype.h"
#include "mblocal.h"
#define MIN(a, b) ((a) < (b) ? (a) : (b))
const char *_RESTRICT_KYWD,
static int _EUC_mbsinit(const mbstate_t *);
typedef struct {
int count[4];
} _EucInfo;
typedef struct {
int set;
int want;
} _EucState;
int
{
int x, new__mb_cur_max;
char *v, *e;
return (EINVAL);
v = (char *)rl->__variable;
while (*v == ' ' || *v == '\t')
++v;
new__mb_cur_max = 0;
for (x = 0; x < 4; ++x) {
if (v == e || !(v = e)) {
return (EINVAL);
}
while (*v == ' ' || *v == '\t')
++v;
if (v == e || !(v = e)) {
return (EINVAL);
}
while (*v == ' ' || *v == '\t')
++v;
}
if (v == e || !(v = e)) {
return (EINVAL);
}
return (0);
}
static int
{
}
#define _SS2 0x008e
#define _SS3 0x008f
static int
{
c &= 0xff;
}
static size_t
{
const char *os;
return ((size_t)-1);
}
if (s == NULL) {
s = "";
n = 1;
}
if (n == 0)
/* Incomplete multibyte sequence */
return ((size_t)-2);
os = s;
--want;
if (--n == 0) {
/* Incomplete multibyte sequence */
return ((size_t)-2);
}
++s;
if (*s == '\0') {
return ((size_t)-1);
}
}
wc = (unsigned char)*s++;
} else {
}
if (*s == '\0') {
return ((size_t)-1);
}
}
if (i < want) {
/* Incomplete multibyte sequence */
return ((size_t)-2);
}
}
static size_t
{
int i, len;
return ((size_t)-1);
}
if (s == NULL)
/* Reset to initial shift state (no-op) */
return (1);
/* Codeset 1: The first byte must have 0x80 in it. */
while (i-- > 0) {
s++;
}
} else {
*(unsigned char *)s = _SS2;
s++;
--i;
/* SS2 designates G2 into GR */
*(unsigned char *)s = _SS3;
s++;
--i;
/* SS3 designates G3 into GR */
} else
goto CodeSet1; /* Bletch */
while (i-- > 0)
}
return (len);
}