Blame iconv/gconv_int.h

Packit 6c4009
/* Copyright (C) 1997-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _GCONV_INT_H
Packit 6c4009
#define _GCONV_INT_H	1
Packit 6c4009
Packit 6c4009
#include "gconv.h"
Packit 6c4009
#include <stdlib.h>		/* For alloca used in macro below.  */
Packit 6c4009
#include <ctype.h>		/* For __toupper_l used in macro below.  */
Packit 6c4009
#include <string.h>		/* For strlen et al used in macro below.  */
Packit 6c4009
#include <libc-lock.h>
Packit 6c4009
Packit 6c4009
__BEGIN_DECLS
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Type to represent search path.  */
Packit 6c4009
struct path_elem
Packit 6c4009
{
Packit 6c4009
  const char *name;
Packit 6c4009
  size_t len;
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
/* Variable with search path for `gconv' implementation.  */
Packit 6c4009
extern struct path_elem *__gconv_path_elem attribute_hidden;
Packit 6c4009
/* Maximum length of a single path element.  */
Packit 6c4009
extern size_t __gconv_max_path_elem_len attribute_hidden;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Structure for alias definition.  Simply two strings.  */
Packit 6c4009
struct gconv_alias
Packit 6c4009
{
Packit 6c4009
  char *fromname;
Packit 6c4009
  char *toname;
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* How many character should be converted in one call?  */
Packit 6c4009
#define GCONV_NCHAR_GOAL	8160
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Structure describing one loaded shared object.  This normally are
Packit 6c4009
   objects to perform conversation but as a special case the db shared
Packit 6c4009
   object is also handled.  */
Packit 6c4009
struct __gconv_loaded_object
Packit 6c4009
{
Packit 6c4009
  /* Name of the object.  It must be the first structure element.  */
Packit 6c4009
  const char *name;
Packit 6c4009
Packit 6c4009
  /* Reference counter for the db functionality.  If no conversion is
Packit 6c4009
     needed we unload the db library.  */
Packit 6c4009
  int counter;
Packit 6c4009
Packit 6c4009
  /* The handle for the shared object.  */
Packit 6c4009
  void *handle;
Packit 6c4009
Packit 6c4009
  /* Pointer to the functions the module defines.  */
Packit 6c4009
  __gconv_fct fct;
Packit 6c4009
  __gconv_init_fct init_fct;
Packit 6c4009
  __gconv_end_fct end_fct;
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Description for an available conversion module.  */
Packit 6c4009
struct gconv_module
Packit 6c4009
{
Packit 6c4009
  const char *from_string;
Packit 6c4009
  const char *to_string;
Packit 6c4009
Packit 6c4009
  int cost_hi;
Packit 6c4009
  int cost_lo;
Packit 6c4009
Packit 6c4009
  const char *module_name;
Packit 6c4009
Packit 6c4009
  struct gconv_module *left;	/* Prefix smaller.  */
Packit 6c4009
  struct gconv_module *same;	/* List of entries with identical prefix.  */
Packit 6c4009
  struct gconv_module *right;	/* Prefix larger.  */
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Flags for `gconv_open'.  */
Packit 6c4009
enum
Packit 6c4009
{
Packit 6c4009
  GCONV_AVOID_NOCONV = 1 << 0
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
/* When GCONV_AVOID_NOCONV is set and no conversion is needed,
Packit 6c4009
   __GCONV_NULCONV should be returned.  */
Packit 6c4009
enum
Packit 6c4009
{
Packit 6c4009
  __GCONV_NULCONV = -1
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
/* Global variables.  */
Packit 6c4009
Packit 6c4009
/* Database of alias names.  */
Packit 6c4009
extern void *__gconv_alias_db attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Array with available modules.  */
Packit 6c4009
extern size_t __gconv_nmodules;
Packit 6c4009
extern struct gconv_module *__gconv_modules_db attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Value of the GCONV_PATH environment variable.  */
Packit 6c4009
extern const char *__gconv_path_envvar attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Lock for the conversion database content.  */
Packit 6c4009
__libc_lock_define (extern, __gconv_lock attribute_hidden)
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* The gconv functions expects the name to be in upper case and complete,
Packit 6c4009
   including the trailing slashes if necessary.  */
Packit 6c4009
#define norm_add_slashes(str,suffix) \
Packit 6c4009
  ({									      \
Packit 6c4009
    const char *cp = (str);						      \
Packit 6c4009
    char *result;							      \
Packit 6c4009
    char *tmp;								      \
Packit 6c4009
    size_t cnt = 0;							      \
Packit 6c4009
    const size_t suffix_len = strlen (suffix);				      \
Packit 6c4009
									      \
Packit 6c4009
    while (*cp != '\0')							      \
Packit 6c4009
      if (*cp++ == '/')							      \
Packit 6c4009
	++cnt;								      \
Packit 6c4009
									      \
Packit 6c4009
    tmp = result = __alloca (cp - (str) + 3 + suffix_len);		      \
Packit 6c4009
    cp = (str);								      \
Packit 6c4009
    while (*cp != '\0')							      \
Packit 6c4009
      *tmp++ = __toupper_l (*cp++, _nl_C_locobj_ptr);			      \
Packit 6c4009
    if (cnt < 2)							      \
Packit 6c4009
      {									      \
Packit 6c4009
	*tmp++ = '/';							      \
Packit 6c4009
	if (cnt < 1)							      \
Packit 6c4009
	  {								      \
Packit 6c4009
	    *tmp++ = '/';						      \
Packit 6c4009
	    if (suffix_len != 0)					      \
Packit 6c4009
	      tmp = __mempcpy (tmp, suffix, suffix_len);		      \
Packit 6c4009
	  }								      \
Packit 6c4009
      }									      \
Packit 6c4009
    *tmp = '\0';							      \
Packit 6c4009
    result;								      \
Packit 6c4009
  })
Packit 6c4009
Packit 6c4009
Packit Service 562438
/* Return in *HANDLE decriptor for transformation from FROMSET to TOSET.  */
Packit Service 562438
extern int __gconv_open (const char *toset, const char *fromset,
Packit Service 562438
			 __gconv_t *handle, int flags)
Packit Service 562438
     attribute_hidden;
Packit Service a0e2fb
Packit 6c4009
/* Free resources associated with transformation descriptor CD.  */
Packit 6c4009
extern int __gconv_close (__gconv_t cd)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Transform at most *INBYTESLEFT bytes from buffer starting at *INBUF
Packit 6c4009
   according to rules described by CD and place up to *OUTBYTESLEFT
Packit 6c4009
   bytes in buffer starting at *OUTBUF.  Return number of non-identical
Packit 6c4009
   conversions in *IRREVERSIBLE if this pointer is not null.  */
Packit 6c4009
extern int __gconv (__gconv_t cd, const unsigned char **inbuf,
Packit 6c4009
		    const unsigned char *inbufend, unsigned char **outbuf,
Packit 6c4009
		    unsigned char *outbufend, size_t *irreversible)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Return in *HANDLE a pointer to an array with *NSTEPS elements describing
Packit 6c4009
   the single steps necessary for transformation from FROMSET to TOSET.  */
Packit 6c4009
extern int __gconv_find_transform (const char *toset, const char *fromset,
Packit 6c4009
				   struct __gconv_step **handle,
Packit 6c4009
				   size_t *nsteps, int flags)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Search for transformation in cache data.  */
Packit 6c4009
extern int __gconv_lookup_cache (const char *toset, const char *fromset,
Packit 6c4009
				 struct __gconv_step **handle, size_t *nsteps,
Packit 6c4009
				 int flags)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Compare the two name for whether they are after alias expansion the
Packit 6c4009
   same.  This function uses the cache and fails if none is
Packit 6c4009
   loaded.  */
Packit 6c4009
extern int __gconv_compare_alias_cache (const char *name1, const char *name2,
Packit 6c4009
					int *result)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Free data associated with a step's structure.  */
Packit 6c4009
extern void __gconv_release_step (struct __gconv_step *step)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Read all the configuration data and cache it.  */
Packit 6c4009
extern void __gconv_read_conf (void) attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Try to read module cache file.  */
Packit 6c4009
extern int __gconv_load_cache (void) attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Retrieve pointer to internal cache.  */
Packit 6c4009
extern void *__gconv_get_cache (void);
Packit 6c4009
Packit 6c4009
/* Retrieve pointer to internal module database.  */
Packit 6c4009
extern struct gconv_module *__gconv_get_modules_db (void);
Packit 6c4009
Packit 6c4009
/* Retrieve pointer to internal alias database.  */
Packit 6c4009
extern void *__gconv_get_alias_db (void);
Packit 6c4009
Packit 6c4009
/* Determine the directories we are looking in.  */
Packit 6c4009
extern void __gconv_get_path (void) attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Comparison function to search alias.  */
Packit 6c4009
extern int __gconv_alias_compare (const void *p1, const void *p2)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Clear reference to transformation step implementations which might
Packit 6c4009
   cause the code to be unloaded.  */
Packit 6c4009
extern int __gconv_close_transform (struct __gconv_step *steps,
Packit 6c4009
				    size_t nsteps)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Free all resources allocated for the transformation record when
Packit 6c4009
   using the cache.  */
Packit 6c4009
extern void __gconv_release_cache (struct __gconv_step *steps, size_t nsteps)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Load shared object named by NAME.  If already loaded increment reference
Packit 6c4009
   count.  */
Packit 6c4009
extern struct __gconv_loaded_object *__gconv_find_shlib (const char *name)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Release shared object.  If no further reference is available unload
Packit 6c4009
   the object.  */
Packit 6c4009
extern void __gconv_release_shlib (struct __gconv_loaded_object *handle)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Fill STEP with information about builtin module with NAME.  */
Packit 6c4009
extern void __gconv_get_builtin_trans (const char *name,
Packit 6c4009
				       struct __gconv_step *step)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
libc_hidden_proto (__gconv_transliterate)
Packit 6c4009
Packit 6c4009
/* If NAME is an codeset alias expand it.  */
Packit 6c4009
extern int __gconv_compare_alias (const char *name1, const char *name2)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Builtin transformations.  */
Packit 6c4009
#ifdef _LIBC
Packit 6c4009
# define __BUILTIN_TRANSFORM(Name) \
Packit 6c4009
  extern int Name (struct __gconv_step *step,				      \
Packit 6c4009
		   struct __gconv_step_data *data,			      \
Packit 6c4009
		   const unsigned char **inbuf,				      \
Packit 6c4009
		   const unsigned char *inbufend,			      \
Packit 6c4009
		   unsigned char **outbufstart, size_t *irreversible,	      \
Packit 6c4009
		   int do_flush, int consume_incomplete)
Packit 6c4009
Packit 6c4009
__BUILTIN_TRANSFORM (__gconv_transform_ascii_internal);
Packit 6c4009
__BUILTIN_TRANSFORM (__gconv_transform_internal_ascii);
Packit 6c4009
__BUILTIN_TRANSFORM (__gconv_transform_utf8_internal);
Packit 6c4009
__BUILTIN_TRANSFORM (__gconv_transform_internal_utf8);
Packit 6c4009
__BUILTIN_TRANSFORM (__gconv_transform_ucs2_internal);
Packit 6c4009
__BUILTIN_TRANSFORM (__gconv_transform_internal_ucs2);
Packit 6c4009
__BUILTIN_TRANSFORM (__gconv_transform_ucs2reverse_internal);
Packit 6c4009
__BUILTIN_TRANSFORM (__gconv_transform_internal_ucs2reverse);
Packit 6c4009
__BUILTIN_TRANSFORM (__gconv_transform_internal_ucs4);
Packit 6c4009
__BUILTIN_TRANSFORM (__gconv_transform_ucs4_internal);
Packit 6c4009
__BUILTIN_TRANSFORM (__gconv_transform_internal_ucs4le);
Packit 6c4009
__BUILTIN_TRANSFORM (__gconv_transform_ucs4le_internal);
Packit 6c4009
__BUILTIN_TRANSFORM (__gconv_transform_internal_utf16);
Packit 6c4009
__BUILTIN_TRANSFORM (__gconv_transform_utf16_internal);
Packit 6c4009
# undef __BUITLIN_TRANSFORM
Packit 6c4009
Packit 6c4009
/* Specialized conversion function for a single byte to INTERNAL, recognizing
Packit 6c4009
   only ASCII characters.  */
Packit 6c4009
extern wint_t __gconv_btwoc_ascii (struct __gconv_step *step, unsigned char c);
Packit 6c4009
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
__END_DECLS
Packit 6c4009
Packit 6c4009
#endif /* gconv_int.h */