mskanji.c revision 105075
1132451Sroberto/* 2132451Sroberto * ja_JP.SJIS locale table for BSD4.4/rune 3290001Sglebius * version 1.0 4290001Sglebius * (C) Sin'ichiro MIYATANI / Phase One, Inc 5290001Sglebius * May 12, 1995 6290001Sglebius * 7290001Sglebius * Redistribution and use in source and binary forms, with or without 8290001Sglebius * modification, are permitted provided that the following conditions 9290001Sglebius * are met: 10290001Sglebius * 1. Redistributions of source code must retain the above copyright 11290001Sglebius * notice, this list of conditions and the following disclaimer. 12290001Sglebius * 2. Redistributions in binary form must reproduce the above copyright 13290001Sglebius * notice, this list of conditions and the following disclaimer in the 14290001Sglebius * documentation and/or other materials provided with the distribution. 15290001Sglebius * 3. All advertising materials mentioning features or use of this software 16290001Sglebius * must display the following acknowledgement: 17290001Sglebius * This product includes software developed by Phase One, Inc. 18290001Sglebius * 4. The name of Phase One, Inc. may be used to endorse or promote products 19290001Sglebius * derived from this software without specific prior written permission. 20290001Sglebius * 21290001Sglebius * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22290001Sglebius * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23290001Sglebius * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24290001Sglebius * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25290001Sglebius * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26290001Sglebius * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27290001Sglebius * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28290001Sglebius * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29290001Sglebius * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30290001Sglebius * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31290001Sglebius * SUCH DAMAGE. 32290001Sglebius */ 33290001Sglebius 34290001Sglebius#if defined(LIBC_SCCS) && !defined(lint) 35290001Sglebiusstatic char sccsid[] = "@(#)mskanji.c 1.0 (Phase One) 5/5/95"; 36290001Sglebius#endif /* LIBC_SCCS and not lint */ 37290001Sglebius#include <sys/cdefs.h> 38290001Sglebius__FBSDID("$FreeBSD: head/lib/libc/locale/mskanji.c 105075 2002-10-14 01:50:45Z tjr $"); 39290001Sglebius 40290001Sglebius#include <sys/types.h> 41290001Sglebius 42290001Sglebius#include <rune.h> 43290001Sglebius#include <stddef.h> 44290001Sglebius#include <stdio.h> 45290001Sglebius#include <stdlib.h> 46290001Sglebius 47290001Sglebiusrune_t _MSKanji_sgetrune(const char *, size_t, char const **); 48290001Sglebiusint _MSKanji_sputrune(rune_t, char *, size_t, char **); 49290001Sglebius 50290001Sglebiusint 51290001Sglebius_MSKanji_init(rl) 52290001Sglebius _RuneLocale *rl; 53290001Sglebius{ 54290001Sglebius rl->sgetrune = _MSKanji_sgetrune; 55290001Sglebius rl->sputrune = _MSKanji_sputrune; 56290001Sglebius 57290001Sglebius _CurrentRuneLocale = rl; 58290001Sglebius __mb_cur_max = 2; 59290001Sglebius return (0); 60290001Sglebius} 61290001Sglebius 62290001Sglebiusrune_t 63290001Sglebius_MSKanji_sgetrune(string, n, result) 64290001Sglebius const char *string; 65290001Sglebius size_t n; 66290001Sglebius char const **result; 67290001Sglebius{ 68290001Sglebius rune_t rune = 0; 69290001Sglebius 70290001Sglebius if (n < 1) { 71290001Sglebius if (result != NULL) 72290001Sglebius *result = string; 73290001Sglebius return (_INVALID_RUNE); 74290001Sglebius } 75290001Sglebius 76290001Sglebius rune = *string++ & 0xff; 77290001Sglebius if ((rune > 0x80 && rune < 0xa0) || 78290001Sglebius (rune >= 0xe0 && rune < 0xfd)) { 79290001Sglebius if (n < 2) { 80290001Sglebius rune = _INVALID_RUNE; 81290001Sglebius --string; 82290001Sglebius } else 83290001Sglebius rune = (rune << 8) | (*string++ & 0xff); 84290001Sglebius } 85290001Sglebius if (result != NULL) 86290001Sglebius *result = string; 87290001Sglebius 88290001Sglebius return (rune); 89290001Sglebius} 90290001Sglebius 91290001Sglebiusint 92290001Sglebius_MSKanji_sputrune(c, string, n, result) 93290001Sglebius rune_t c; 94290001Sglebius char *string, **result; 95290001Sglebius size_t n; 96290001Sglebius{ 97290001Sglebius int len, i; 98290001Sglebius 99290001Sglebius len = (c > 0x100) ? 2 : 1; 100290001Sglebius if (n < len) { 101290001Sglebius if (result != NULL) 102290001Sglebius *result = NULL; 103290001Sglebius } else { 104290001Sglebius if (result != NULL) 105290001Sglebius *result = string + len; 106290001Sglebius for (i = len; i-- > 0; ) 107290001Sglebius *string++ = c >> (i << 3); 108290001Sglebius } 109290001Sglebius 110290001Sglebius return (len); 111290001Sglebius} 112290001Sglebius