Home | History | Annotate | Line # | Download | only in citrus
citrus_stdenc.h revision 1.2
      1 /*	$NetBSD: citrus_stdenc.h,v 1.2 2003/06/26 12:09:56 tshiozak Exp $	*/
      2 
      3 /*-
      4  * Copyright (c)2003 Citrus Project,
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  *
     28  */
     29 
     30 #ifndef _CITRUS_STDENC_H_
     31 #define _CITRUS_STDENC_H_
     32 
     33 struct _citrus_stdenc;
     34 struct _citrus_stdenc_ops;
     35 struct _citrus_stdenc_traits;
     36 
     37 #include "citrus_stdenc_local.h"
     38 
     39 __BEGIN_DECLS
     40 int _citrus_stdenc_open(struct _citrus_stdenc * __restrict * __restrict,
     41 			char const * __restrict,
     42 			const void * __restrict, size_t);
     43 void _citrus_stdenc_close(struct _citrus_stdenc *);
     44 __END_DECLS
     45 
     46 static __inline int
     47 _citrus_stdenc_init_state(struct _citrus_stdenc * __restrict ce,
     48 			  void * __restrict ps)
     49 {
     50 	_DIAGASSERT(ce && ce->ci_ops && ce->ce_ops->eo_init_state);
     51 	return (*ce->ce_ops->eo_init_state)(ce, ps);
     52 }
     53 
     54 static __inline int
     55 _citrus_stdenc_mbtocs(struct _citrus_stdenc * __restrict ce,
     56 		      _citrus_csid_t * __restrict csid,
     57 		      _citrus_index_t * __restrict idx,
     58 		      const char ** __restrict s, size_t n,
     59 		      void * __restrict ps, size_t * __restrict nresult)
     60 {
     61 	_DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_mbtocs);
     62 	return (*ce->ce_ops->eo_mbtocs)(ce, csid, idx, s, n, ps, nresult);
     63 }
     64 
     65 static __inline int
     66 _citrus_stdenc_cstomb(struct _citrus_stdenc * __restrict ce,
     67 		      char * __restrict s, size_t n,
     68 		      _citrus_csid_t csid, _citrus_index_t idx,
     69 		      void * __restrict ps, size_t * __restrict nresult)
     70 {
     71 	_DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_cstomb);
     72 	return (*ce->ce_ops->eo_cstomb)(ce, s, n, csid, idx, ps, nresult);
     73 }
     74 
     75 static __inline int
     76 _citrus_stdenc_mbtowc(struct _citrus_stdenc * __restrict ce,
     77 		      _citrus_wc_t * __restrict wc,
     78 		      const char ** __restrict s, size_t n,
     79 		      void * __restrict ps, size_t * __restrict nresult)
     80 {
     81 	_DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_mbtocs);
     82 	return (*ce->ce_ops->eo_mbtowc)(ce, wc, s, n, ps, nresult);
     83 }
     84 
     85 static __inline int
     86 _citrus_stdenc_wctomb(struct _citrus_stdenc * __restrict ce,
     87 		      char * __restrict s, size_t n, _citrus_wc_t wc,
     88 		      void * __restrict ps, size_t * __restrict nresult)
     89 {
     90 	_DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_cstomb);
     91 	return (*ce->ce_ops->eo_wctomb)(ce, s, n, wc, ps, nresult);
     92 }
     93 
     94 static __inline int
     95 _citrus_stdenc_put_state_reset(struct _citrus_stdenc * __restrict ce,
     96 			       char * __restrict s, size_t n,
     97 			       void * __restrict ps,
     98 			       size_t * __restrict nresult)
     99 {
    100 	_DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_put_state_reset);
    101 	return (*ce->ce_ops->eo_put_state_reset)(ce, s, n, ps, nresult);
    102 }
    103 
    104 static __inline size_t
    105 _citrus_stdenc_get_state_size(struct _citrus_stdenc *ce)
    106 {
    107 	_DIAGASSERT(ce && ce->ce_traits);
    108 	return ce->ce_traits->et_state_size;
    109 }
    110 
    111 static __inline size_t
    112 _citrus_stdenc_get_mb_cur_max(struct _citrus_stdenc *ce)
    113 {
    114 	_DIAGASSERT(ce && ce->ce_traits);
    115 	return ce->ce_traits->et_mb_cur_max;
    116 }
    117 
    118 #endif
    119