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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc2/] [newlib/] [libc/] [stdlib/] [a64l.c] - Diff between revs 207 and 520

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

Rev 207 Rev 520
/*
/*
FUNCTION
FUNCTION
<<a64l>>, <<l64a>>---convert between radix-64 ASCII string and long
<<a64l>>, <<l64a>>---convert between radix-64 ASCII string and long
 
 
INDEX
INDEX
        a64l
        a64l
INDEX
INDEX
        l64a
        l64a
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <stdlib.h>
        #include <stdlib.h>
        long a64l(const char *<[input]>);
        long a64l(const char *<[input]>);
        char *l64a(long <[input]>);
        char *l64a(long <[input]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <stdlib.h>
        #include <stdlib.h>
        long a64l(<[input]>)
        long a64l(<[input]>)
        const char *<[input]>;
        const char *<[input]>;
 
 
        char *l64a(<[input]>)
        char *l64a(<[input]>)
        long <[input]>;
        long <[input]>;
 
 
DESCRIPTION
DESCRIPTION
Conversion is performed between long and radix-64 characters.  The
Conversion is performed between long and radix-64 characters.  The
<<l64a>> routine transforms up to 32 bits of input value starting from
<<l64a>> routine transforms up to 32 bits of input value starting from
least significant bits to the most significant bits.  The input value
least significant bits to the most significant bits.  The input value
is split up into a maximum of 5 groups of 6 bits and possibly one
is split up into a maximum of 5 groups of 6 bits and possibly one
group of 2 bits (bits 31 and 30).
group of 2 bits (bits 31 and 30).
 
 
Each group of 6 bits forms a value from 0--63 which is translated into
Each group of 6 bits forms a value from 0--63 which is translated into
a character as follows:
a character as follows:
 
 
O+
O+
o     0 = '.'
o     0 = '.'
o     1 = '/'
o     1 = '/'
o     2--11 = '0' to '9'
o     2--11 = '0' to '9'
o     12--37 = 'A' to 'Z'
o     12--37 = 'A' to 'Z'
o     38--63 = 'a' to 'z'
o     38--63 = 'a' to 'z'
O-
O-
 
 
When the remaining bits are zero or all bits have been translated, a
When the remaining bits are zero or all bits have been translated, a
null terminator is appended to the string.  An input value of 0
null terminator is appended to the string.  An input value of 0
results in the empty string.
results in the empty string.
 
 
The <<a64l>> function performs the reverse translation.  Each
The <<a64l>> function performs the reverse translation.  Each
character is used to generate a 6-bit value for up to 30 bits and then
character is used to generate a 6-bit value for up to 30 bits and then
a 2-bit value to complete a 32-bit result.  The null terminator means
a 2-bit value to complete a 32-bit result.  The null terminator means
that the remaining digits are 0.  An empty input string or NULL string
that the remaining digits are 0.  An empty input string or NULL string
results in 0L.  An invalid string results in undefined behavior.  If
results in 0L.  An invalid string results in undefined behavior.  If
the size of a long is greater than 32 bits, the result is sign-extended.
the size of a long is greater than 32 bits, the result is sign-extended.
 
 
RETURNS
RETURNS
<<l64a>> returns a null-terminated string of 0 to 6 characters.
<<l64a>> returns a null-terminated string of 0 to 6 characters.
<<a64l>> returns the 32-bit translated value from the input character string.
<<a64l>> returns the 32-bit translated value from the input character string.
 
 
PORTABILITY
PORTABILITY
<<l64a>> and <<a64l>> are non-ANSI and are defined by the Single Unix Specification.
<<l64a>> and <<a64l>> are non-ANSI and are defined by the Single Unix Specification.
 
 
Supporting OS subroutines required: None.
Supporting OS subroutines required: None.
*/
*/
 
 
#include <_ansi.h>
#include <_ansi.h>
#include <stdlib.h>
#include <stdlib.h>
#include <limits.h>
#include <limits.h>
 
 
long
long
_DEFUN (a64l, (input),
_DEFUN (a64l, (input),
        const char *input)
        const char *input)
{
{
  const char *ptr;
  const char *ptr;
  char ch;
  char ch;
  int i, digit;
  int i, digit;
  unsigned long result = 0;
  unsigned long result = 0;
 
 
  if (input == NULL)
  if (input == NULL)
    return 0;
    return 0;
 
 
  ptr = input;
  ptr = input;
 
 
  /* it easiest to go from most significant digit to least so find end of input or up
  /* it easiest to go from most significant digit to least so find end of input or up
     to 6 characters worth */
     to 6 characters worth */
  for (i = 0; i < 6; ++i)
  for (i = 0; i < 6; ++i)
    {
    {
      if (*ptr)
      if (*ptr)
        ++ptr;
        ++ptr;
    }
    }
 
 
  while (ptr > input)
  while (ptr > input)
    {
    {
      ch = *(--ptr);
      ch = *(--ptr);
 
 
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
      if (ch >= 'a')
      if (ch >= 'a')
        digit = (ch - 'a') + 38;
        digit = (ch - 'a') + 38;
      else if (ch >= 'A')
      else if (ch >= 'A')
        digit = (ch - 'A') + 12;
        digit = (ch - 'A') + 12;
      else if (ch >= '0')
      else if (ch >= '0')
        digit = (ch - '0') + 2;
        digit = (ch - '0') + 2;
      else if (ch == '/')
      else if (ch == '/')
        digit = 1;
        digit = 1;
      else
      else
        digit = 0;
        digit = 0;
#else /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) */
#else /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) */
      switch (ch)
      switch (ch)
        {
        {
        case '/':
        case '/':
          digit = 1;
          digit = 1;
          break;
          break;
        case '0':
        case '0':
        case '1':
        case '1':
        case '2':
        case '2':
        case '3':
        case '3':
        case '4':
        case '4':
        case '5':
        case '5':
        case '6':
        case '6':
        case '7':
        case '7':
        case '8':
        case '8':
        case '9':
        case '9':
          digit = (ch - '0') + 2;
          digit = (ch - '0') + 2;
          break;
          break;
        case 'A':
        case 'A':
        case 'B':
        case 'B':
        case 'C':
        case 'C':
        case 'D':
        case 'D':
        case 'E':
        case 'E':
        case 'F':
        case 'F':
        case 'G':
        case 'G':
        case 'H':
        case 'H':
        case 'I':
        case 'I':
        case 'J':
        case 'J':
        case 'K':
        case 'K':
        case 'L':
        case 'L':
        case 'M':
        case 'M':
        case 'N':
        case 'N':
        case 'O':
        case 'O':
        case 'P':
        case 'P':
        case 'Q':
        case 'Q':
        case 'R':
        case 'R':
        case 'S':
        case 'S':
        case 'T':
        case 'T':
        case 'U':
        case 'U':
        case 'V':
        case 'V':
        case 'W':
        case 'W':
        case 'X':
        case 'X':
        case 'Y':
        case 'Y':
        case 'Z':
        case 'Z':
          digit = (ch - 'A') + 12;
          digit = (ch - 'A') + 12;
          break;
          break;
        case 'a':
        case 'a':
        case 'b':
        case 'b':
        case 'c':
        case 'c':
        case 'd':
        case 'd':
        case 'e':
        case 'e':
        case 'f':
        case 'f':
        case 'g':
        case 'g':
        case 'h':
        case 'h':
        case 'i':
        case 'i':
        case 'j':
        case 'j':
        case 'k':
        case 'k':
        case 'l':
        case 'l':
        case 'm':
        case 'm':
        case 'n':
        case 'n':
        case 'o':
        case 'o':
        case 'p':
        case 'p':
        case 'q':
        case 'q':
        case 'r':
        case 'r':
        case 's':
        case 's':
        case 't':
        case 't':
        case 'u':
        case 'u':
        case 'v':
        case 'v':
        case 'w':
        case 'w':
        case 'x':
        case 'x':
        case 'y':
        case 'y':
        case 'z':
        case 'z':
          digit = (ch - 'a') + 38;
          digit = (ch - 'a') + 38;
          break;
          break;
        default:
        default:
          digit = 0;
          digit = 0;
          break;
          break;
        }
        }
#endif /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) */ 
#endif /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) */ 
 
 
      result = (result << 6) + digit;
      result = (result << 6) + digit;
    }
    }
 
 
#if LONG_MAX > 2147483647
#if LONG_MAX > 2147483647
  /* for implementations where long is > 32 bits, the result must be sign-extended */
  /* for implementations where long is > 32 bits, the result must be sign-extended */
  if (result & 0x80000000)
  if (result & 0x80000000)
      return (((long)-1 >> 32) << 32) + result;
      return (((long)-1 >> 32) << 32) + result;
#endif
#endif
 
 
  return result;
  return result;
}
}
 
 
 
 
 
 
 
 
 
 

powered by: WebSVN 2.1.0

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