OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [gdb-5.0/] [readline/] [nls.c] - Diff between revs 579 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 579 Rev 1765
/* nls.c -- skeletal internationalization code. */
/* nls.c -- skeletal internationalization code. */
 
 
/* Copyright (C) 1996 Free Software Foundation, Inc.
/* Copyright (C) 1996 Free Software Foundation, Inc.
 
 
   This file is part of the GNU Readline Library, a library for
   This file is part of the GNU Readline Library, a library for
   reading lines of text with interactive input and history editing.
   reading lines of text with interactive input and history editing.
 
 
   The GNU Readline Library is free software; you can redistribute it
   The GNU Readline Library is free software; you can redistribute it
   and/or modify it under the terms of the GNU General Public License
   and/or modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 1, or
   as published by the Free Software Foundation; either version 1, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   The GNU Readline Library is distributed in the hope that it will be
   The GNU Readline Library is distributed in the hope that it will be
   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   The GNU General Public License is often shipped with GNU software, and
   The GNU General Public License is often shipped with GNU software, and
   is generally kept in a file called COPYING or LICENSE.  If you do not
   is generally kept in a file called COPYING or LICENSE.  If you do not
   have a copy of the license, write to the Free Software Foundation,
   have a copy of the license, write to the Free Software Foundation,
   675 Mass Ave, Cambridge, MA 02139, USA. */
   675 Mass Ave, Cambridge, MA 02139, USA. */
#define READLINE_LIBRARY
#define READLINE_LIBRARY
 
 
#if defined (HAVE_CONFIG_H)
#if defined (HAVE_CONFIG_H)
#  include <config.h>
#  include <config.h>
#endif
#endif
 
 
#include <sys/types.h>
#include <sys/types.h>
 
 
#if defined (HAVE_UNISTD_H)
#if defined (HAVE_UNISTD_H)
#  include <unistd.h>
#  include <unistd.h>
#endif /* HAVE_UNISTD_H */
#endif /* HAVE_UNISTD_H */
 
 
#if defined (HAVE_STDLIB_H)
#if defined (HAVE_STDLIB_H)
#  include <stdlib.h>
#  include <stdlib.h>
#else
#else
#  include "ansi_stdlib.h"
#  include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */
#endif /* HAVE_STDLIB_H */
 
 
#if defined (HAVE_LOCALE_H)
#if defined (HAVE_LOCALE_H)
#  include <locale.h>
#  include <locale.h>
#endif
#endif
 
 
#include <ctype.h>
#include <ctype.h>
 
 
#include "rldefs.h"
#include "rldefs.h"
 
 
extern int _rl_convert_meta_chars_to_ascii;
extern int _rl_convert_meta_chars_to_ascii;
extern int _rl_output_meta_chars;
extern int _rl_output_meta_chars;
extern int _rl_meta_flag;
extern int _rl_meta_flag;
 
 
/* Functions imported from shell.c */
/* Functions imported from shell.c */
extern char *get_env_value ();
extern char *get_env_value ();
 
 
#if !defined (HAVE_SETLOCALE)    
#if !defined (HAVE_SETLOCALE)    
/* A list of legal values for the LANG or LC_CTYPE environment variables.
/* A list of legal values for the LANG or LC_CTYPE environment variables.
   If a locale name in this list is the value for the LC_ALL, LC_CTYPE,
   If a locale name in this list is the value for the LC_ALL, LC_CTYPE,
   or LANG environment variable (using the first of those with a value),
   or LANG environment variable (using the first of those with a value),
   readline eight-bit mode is enabled. */
   readline eight-bit mode is enabled. */
static char *legal_lang_values[] =
static char *legal_lang_values[] =
{
{
 "iso88591",
 "iso88591",
 "iso88592",
 "iso88592",
 "iso88593",
 "iso88593",
 "iso88594",
 "iso88594",
 "iso88595",
 "iso88595",
 "iso88596",
 "iso88596",
 "iso88597",
 "iso88597",
 "iso88598",
 "iso88598",
 "iso88599",
 "iso88599",
 "iso885910",
 "iso885910",
 "koi8r",
 "koi8r",
 "koi8-r",
 "koi8-r",
  0
  0
};
};
 
 
static char *normalize_codeset ();
static char *normalize_codeset ();
static char *find_codeset ();
static char *find_codeset ();
#endif /* !HAVE_SETLOCALE */
#endif /* !HAVE_SETLOCALE */
 
 
/* Check for LC_ALL, LC_CTYPE, and LANG and use the first with a value
/* Check for LC_ALL, LC_CTYPE, and LANG and use the first with a value
   to decide the defaults for 8-bit character input and output.  Returns
   to decide the defaults for 8-bit character input and output.  Returns
   1 if we set eight-bit mode. */
   1 if we set eight-bit mode. */
int
int
_rl_init_eightbit ()
_rl_init_eightbit ()
{
{
/* If we have setlocale(3), just check the current LC_CTYPE category
/* If we have setlocale(3), just check the current LC_CTYPE category
   value, and go into eight-bit mode if it's not C or POSIX. */
   value, and go into eight-bit mode if it's not C or POSIX. */
#if defined (HAVE_SETLOCALE)
#if defined (HAVE_SETLOCALE)
  char *t;
  char *t;
 
 
  /* Set the LC_CTYPE locale category from environment variables. */
  /* Set the LC_CTYPE locale category from environment variables. */
  t = setlocale (LC_CTYPE, "");
  t = setlocale (LC_CTYPE, "");
  if (t && *t && (t[0] != 'C' || t[1]) && (STREQ (t, "POSIX") == 0))
  if (t && *t && (t[0] != 'C' || t[1]) && (STREQ (t, "POSIX") == 0))
    {
    {
      _rl_meta_flag = 1;
      _rl_meta_flag = 1;
      _rl_convert_meta_chars_to_ascii = 0;
      _rl_convert_meta_chars_to_ascii = 0;
      _rl_output_meta_chars = 1;
      _rl_output_meta_chars = 1;
      return (1);
      return (1);
    }
    }
  else
  else
    return (0);
    return (0);
 
 
#else /* !HAVE_SETLOCALE */
#else /* !HAVE_SETLOCALE */
  char *lspec, *t;
  char *lspec, *t;
  int i;
  int i;
 
 
  /* We don't have setlocale.  Finesse it.  Check the environment for the
  /* We don't have setlocale.  Finesse it.  Check the environment for the
     appropriate variables and set eight-bit mode if they have the right
     appropriate variables and set eight-bit mode if they have the right
     values. */
     values. */
  lspec = get_env_value ("LC_ALL");
  lspec = get_env_value ("LC_ALL");
  if (lspec == 0) lspec = get_env_value ("LC_CTYPE");
  if (lspec == 0) lspec = get_env_value ("LC_CTYPE");
  if (lspec == 0) lspec = get_env_value ("LANG");
  if (lspec == 0) lspec = get_env_value ("LANG");
  if (lspec == 0 || (t = normalize_codeset (lspec)) == 0)
  if (lspec == 0 || (t = normalize_codeset (lspec)) == 0)
    return (0);
    return (0);
  for (i = 0; t && legal_lang_values[i]; i++)
  for (i = 0; t && legal_lang_values[i]; i++)
    if (STREQ (t, legal_lang_values[i]))
    if (STREQ (t, legal_lang_values[i]))
      {
      {
        _rl_meta_flag = 1;
        _rl_meta_flag = 1;
        _rl_convert_meta_chars_to_ascii = 0;
        _rl_convert_meta_chars_to_ascii = 0;
        _rl_output_meta_chars = 1;
        _rl_output_meta_chars = 1;
        break;
        break;
      }
      }
  free (t);
  free (t);
  return (legal_lang_values[i] ? 1 : 0);
  return (legal_lang_values[i] ? 1 : 0);
 
 
#endif /* !HAVE_SETLOCALE */
#endif /* !HAVE_SETLOCALE */
}
}
 
 
#if !defined (HAVE_SETLOCALE)
#if !defined (HAVE_SETLOCALE)
static char *
static char *
normalize_codeset (codeset)
normalize_codeset (codeset)
     char *codeset;
     char *codeset;
{
{
  size_t namelen, i;
  size_t namelen, i;
  int len, all_digits;
  int len, all_digits;
  char *wp, *retval;
  char *wp, *retval;
 
 
  codeset = find_codeset (codeset, &namelen);
  codeset = find_codeset (codeset, &namelen);
 
 
  if (codeset == 0)
  if (codeset == 0)
    return (codeset);
    return (codeset);
 
 
  all_digits = 1;
  all_digits = 1;
  for (len = 0, i = 0; i < namelen; i++)
  for (len = 0, i = 0; i < namelen; i++)
    {
    {
      if (isalnum (codeset[i]))
      if (isalnum (codeset[i]))
        {
        {
          len++;
          len++;
          all_digits &= isdigit (codeset[i]);
          all_digits &= isdigit (codeset[i]);
        }
        }
    }
    }
 
 
  retval = (char *)malloc ((all_digits ? 3 : 0) + len + 1);
  retval = (char *)malloc ((all_digits ? 3 : 0) + len + 1);
  if (retval == 0)
  if (retval == 0)
    return ((char *)0);
    return ((char *)0);
 
 
  wp = retval;
  wp = retval;
  /* Add `iso' to beginning of an all-digit codeset */
  /* Add `iso' to beginning of an all-digit codeset */
  if (all_digits)
  if (all_digits)
    {
    {
      *wp++ = 'i';
      *wp++ = 'i';
      *wp++ = 's';
      *wp++ = 's';
      *wp++ = 'o';
      *wp++ = 'o';
    }
    }
 
 
  for (i = 0; i < namelen; i++)
  for (i = 0; i < namelen; i++)
    if (isalpha (codeset[i]))
    if (isalpha (codeset[i]))
      *wp++ = (isupper (codeset[i])) ? tolower (codeset[i]) : codeset[i];
      *wp++ = (isupper (codeset[i])) ? tolower (codeset[i]) : codeset[i];
    else if (isdigit (codeset[i]))
    else if (isdigit (codeset[i]))
      *wp++ = codeset[i];
      *wp++ = codeset[i];
  *wp = '\0';
  *wp = '\0';
 
 
  return retval;
  return retval;
}
}
 
 
/* Isolate codeset portion of locale specification. */
/* Isolate codeset portion of locale specification. */
static char *
static char *
find_codeset (name, lenp)
find_codeset (name, lenp)
     char *name;
     char *name;
     size_t *lenp;
     size_t *lenp;
{
{
  char *cp, *language, *result;
  char *cp, *language, *result;
 
 
  cp = language = name;
  cp = language = name;
  result = (char *)0;
  result = (char *)0;
 
 
  while (*cp && *cp != '_' && *cp != '@' && *cp != '+' && *cp != ',')
  while (*cp && *cp != '_' && *cp != '@' && *cp != '+' && *cp != ',')
    cp++;
    cp++;
 
 
  /* This does not make sense: language has to be specified.  As
  /* This does not make sense: language has to be specified.  As
     an exception we allow the variable to contain only the codeset
     an exception we allow the variable to contain only the codeset
     name.  Perhaps there are funny codeset names.  */
     name.  Perhaps there are funny codeset names.  */
  if (language == cp)
  if (language == cp)
    {
    {
      *lenp = strlen (language);
      *lenp = strlen (language);
      result = language;
      result = language;
    }
    }
  else
  else
    {
    {
      /* Next is the territory. */
      /* Next is the territory. */
      if (*cp == '_')
      if (*cp == '_')
        do
        do
          ++cp;
          ++cp;
        while (*cp && *cp != '.' && *cp != '@' && *cp != '+' && *cp != ',' && *cp != '_');
        while (*cp && *cp != '.' && *cp != '@' && *cp != '+' && *cp != ',' && *cp != '_');
 
 
      /* Now, finally, is the codeset. */
      /* Now, finally, is the codeset. */
      result = cp;
      result = cp;
      if (*cp == '.')
      if (*cp == '.')
        do
        do
          ++cp;
          ++cp;
        while (*cp && *cp != '@');
        while (*cp && *cp != '@');
 
 
      if (cp - result > 2)
      if (cp - result > 2)
        {
        {
          result++;
          result++;
          *lenp = cp - result;
          *lenp = cp - result;
        }
        }
      else
      else
        {
        {
          *lenp = strlen (language);
          *lenp = strlen (language);
          result = language;
          result = language;
        }
        }
    }
    }
 
 
  return result;
  return result;
}
}
#endif /* !HAVE_SETLOCALE */
#endif /* !HAVE_SETLOCALE */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.