2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A
2N/A/*
2N/A * Copyright (c) 1997, by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*LINTLIBRARY*/
2N/A
2N/A#include <sys/types.h>
2N/A#include <widec.h>
2N/A#include <ctype.h>
2N/A#include "curses_wchar.h"
2N/A
2N/Aint
2N/A_curs_wctomb(char *s, wchar_t wchar)
2N/A{
2N/A char *olds = s;
2N/A int size, index;
2N/A unsigned char d;
2N/A if (!s)
2N/A return (0);
2N/A if (wchar <= 0177 || (wchar <= 0377 && (iscntrl((int)wchar) != 0))) {
2N/A /* LINTED */
2N/A *s++ = (char)wchar;
2N/A return (1);
2N/A }
2N/A switch (wchar & EUCMASK) {
2N/A
2N/A case P11:
2N/A size = eucw1;
2N/A break;
2N/A
2N/A case P01:
2N/A /* LINTED */
2N/A *s++ = (char)SS2;
2N/A size = eucw2;
2N/A break;
2N/A
2N/A case P10:
2N/A /* LINTED */
2N/A *s++ = (char)SS3;
2N/A size = eucw3;
2N/A break;
2N/A
2N/A default:
2N/A return (-1);
2N/A }
2N/A if ((index = size) <= 0)
2N/A return (-1);
2N/A while (index--) {
2N/A /* LINTED */
2N/A d = wchar | 0200;
2N/A wchar >>= 7;
2N/A if (iscntrl(d))
2N/A return (-1);
2N/A s[index] = d;
2N/A }
2N/A /* LINTED */
2N/A return ((int)(s - olds) + size);
2N/A}