hbase

heirloom base
git clone git://git.2f30.org/hbase
Log | Files | Refs | README

y5.c (1723B)


      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License, Version 1.0 only
      6  * (the "License").  You may not use this file except in compliance
      7  * with the License.
      8  *
      9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10  * or http://www.opensolaris.org/os/licensing.
     11  * See the License for the specific language governing permissions
     12  * and limitations under the License.
     13  *
     14  * When distributing Covered Code, include this CDDL HEADER in each
     15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16  * If applicable, add the following below this CDDL HEADER, with the
     17  * fields enclosed by brackets "[]" replaced with your own identifying
     18  * information: Portions Copyright [yyyy] [name of copyright owner]
     19  *
     20  * CDDL HEADER END
     21  */
     22 /*
     23  * Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
     24  *
     25  * Sccsid @(#)y5.c	1.1 (gritter) 6/25/05
     26  */
     27 #include <stdlib.h>
     28 #include <wchar.h>
     29 #include <stdio.h>
     30 #include <limits.h>
     31 #include <errno.h>
     32 
     33 extern int	error(char *, ...);
     34 
     35 /*
     36  * This is like getwc() but issues an error message when an illegal
     37  * byte sequence is encountered.
     38  */
     39 wint_t
     40 yacc_getwc(FILE *fp)
     41 {
     42 	wint_t	wc;
     43 
     44 	if ((wc = getwc(fp)) != WEOF)
     45 		return wc;
     46 	if (ferror(fp) && errno == EILSEQ)
     47 		error("illegal byte sequence");
     48 	return wc;
     49 }
     50 
     51 /*
     52  * A substitute for putwc(), to ensure that stdio output FILE objects
     53  * are always byte-oriented.
     54  */
     55 wint_t
     56 yacc_putwc(wchar_t wc, FILE *fp)
     57 {
     58 	char	mb[MB_LEN_MAX];
     59 	int	i, n;
     60 
     61 	if ((n = wctomb(mb, wc)) < 0) {
     62 		wctomb(mb, 0);
     63 		errno = EILSEQ;
     64 		return WEOF;
     65 	}
     66 	for (i = 0; i < n; i++)
     67 		if (putc(mb[i]&0377, fp) == EOF)
     68 			return WEOF;
     69 	return wc;
     70 }