New HAL and SimpleMAC for STM32W108.
This commit is contained in:
parent
c9af578eab
commit
eb588f1aec
89 changed files with 1503 additions and 1883 deletions
80
cpu/stm32w108/e_stdio/src/_SP_printf.c
Normal file
80
cpu/stm32w108/e_stdio/src/_SP_printf.c
Normal file
|
@ -0,0 +1,80 @@
|
|||
#define _SMALL_PRINFT
|
||||
|
||||
#ifdef INTEGER_ONLY
|
||||
#define _vfprintf_r _vfiprintf_r
|
||||
#define _vfprintf _vfiprintf
|
||||
#define vfprintf vfiprintf
|
||||
#endif
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef _SMALL_PRINTF
|
||||
#include "local.h"
|
||||
#endif
|
||||
|
||||
#ifdef _HAVE_STDC
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
#ifndef _SMALL_PRINTF
|
||||
|
||||
#ifdef _HAVE_STDC
|
||||
int
|
||||
_printf_r (struct _reent *ptr, const char *fmt, ...)
|
||||
#else
|
||||
int
|
||||
_printf_r (ptr, fmt, va_alist)
|
||||
struct _reent *ptr;
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
//_REENT_SMALL_CHECK_INIT(_stdout_r (ptr));
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap);
|
||||
va_end (ap);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
#ifdef _HAVE_STDC
|
||||
int
|
||||
printf (const char *fmt, ...)
|
||||
#else
|
||||
int
|
||||
printf (fmt, va_alist)
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
//_REENT_SMALL_CHECK_INIT(_stdout_r (_REENT));
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
#ifndef _SMALL_PRINTF
|
||||
ret = vfprintf (_stdout_r (_REENT), fmt, ap);
|
||||
#else
|
||||
ret = vfprintf (0, fmt, ap);
|
||||
#endif
|
||||
va_end (ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* ! _REENT_ONLY */
|
43
cpu/stm32w108/e_stdio/src/_SP_puts.c
Normal file
43
cpu/stm32w108/e_stdio/src/_SP_puts.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include <stdio.h>
|
||||
|
||||
|
||||
void __io_putchar ( char );
|
||||
|
||||
void _SMALL_PRINTF_puts(const char *ptr, int len, FILE *fp)
|
||||
{
|
||||
if ( fp && ( fp->_file == -1 ) /* No file => sprintf */
|
||||
&& (fp->_flags & (__SWR | __SSTR) ) )
|
||||
{
|
||||
char *str = fp->_p;
|
||||
|
||||
for ( ; len ; len-- )
|
||||
{
|
||||
*str ++ = *ptr++;
|
||||
}
|
||||
fp->_p = str;
|
||||
}
|
||||
else /* file => printf */
|
||||
{
|
||||
for ( ; len ; len-- )
|
||||
__io_putchar ( *ptr++ );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int puts(const char *str)
|
||||
{
|
||||
#if 1 //VC090825: cleaner and faster version
|
||||
int len = 0;
|
||||
while ( str && (*str) )
|
||||
{
|
||||
__io_putchar ( *(str++) );
|
||||
len++;
|
||||
}
|
||||
#else //VC090825: cleaner, lighter and faster version
|
||||
int len = strlen ( str );
|
||||
_SMALL_PRINTF_puts(str, len, 0) ;
|
||||
#endif //VC090825: cleaner, lighter and faster version
|
||||
__io_putchar ( '\n' );
|
||||
return len;
|
||||
}
|
||||
|
124
cpu/stm32w108/e_stdio/src/_SP_snprintf.c
Normal file
124
cpu/stm32w108/e_stdio/src/_SP_snprintf.c
Normal file
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
/* doc in _SP_sprintf.c */
|
||||
/* This code created by modifying _SP_sprintf.c so copyright inherited. */
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef _HAVE_STDC
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <_ansi.h>
|
||||
|
||||
#ifndef _SMALL_PRINTF
|
||||
#include "local.h"
|
||||
#else
|
||||
#ifdef INTEGER_ONLY
|
||||
#define _vfprintf_r _vfiprintf_r
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef _SMALL_PRINTF
|
||||
int
|
||||
#ifdef _HAVE_STDC
|
||||
_DEFUN (_snprintf_r, (ptr, str, size, fmt), struct _reent *ptr _AND char *str _AND size_t size _AND _CONST char *fmt _DOTS)
|
||||
#else
|
||||
_snprintf_r (ptr, str, size, fmt, va_alist)
|
||||
struct _reent *ptr;
|
||||
char *str;
|
||||
size_t size;
|
||||
_CONST char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
FILE f;
|
||||
|
||||
if (size > INT_MAX)
|
||||
{
|
||||
ptr->_errno = EOVERFLOW;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
f._flags = __SWR | __SSTR;
|
||||
f._bf._base = f._p = (unsigned char *) str;
|
||||
f._bf._size = f._w = (size > 0 ? size - 1 : 0);
|
||||
f._file = -1; /* No file. */
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = _vfprintf_r (ptr, &f, fmt, ap);
|
||||
va_end (ap);
|
||||
if (ret < EOF)
|
||||
ptr->_errno = EOVERFLOW;
|
||||
if (size > 0)
|
||||
*f._p = 0;
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
int
|
||||
#ifdef _HAVE_STDC
|
||||
_DEFUN (snprintf, (str, size, fmt), char *str _AND size_t size _AND _CONST char *fmt _DOTS)
|
||||
#else
|
||||
snprintf (str, size, fmt, va_alist)
|
||||
char *str;
|
||||
size_t size;
|
||||
_CONST char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
FILE f;
|
||||
|
||||
struct _reent *ptr = _REENT;
|
||||
|
||||
if (size > INT_MAX)
|
||||
{
|
||||
ptr->_errno = EOVERFLOW;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
f._flags = __SWR | __SSTR;
|
||||
f._bf._base = f._p = (unsigned char *) str;
|
||||
f._bf._size = f._w = (size > 0 ? size - 1 : 0);
|
||||
f._file = -1; /* No file. */
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = _vfprintf_r (ptr, &f, fmt, ap);
|
||||
va_end (ap);
|
||||
if (ret < EOF)
|
||||
ptr->_errno = EOVERFLOW;
|
||||
if (size > 0)
|
||||
*f._p = 0;
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
393
cpu/stm32w108/e_stdio/src/_SP_sprintf.c
Normal file
393
cpu/stm32w108/e_stdio/src/_SP_sprintf.c
Normal file
|
@ -0,0 +1,393 @@
|
|||
/*
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
FUNCTION
|
||||
<<printf>>, <<fprintf>>, <<asprintf>>, <<sprintf>>, <<snprintf>>---format output
|
||||
INDEX
|
||||
fprintf
|
||||
INDEX
|
||||
printf
|
||||
INDEX
|
||||
asprintf
|
||||
INDEX
|
||||
sprintf
|
||||
INDEX
|
||||
snprintf
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdio.h>
|
||||
|
||||
int printf(const char *<[format]> [, <[arg]>, ...]);
|
||||
int fprintf(FILE *<[fd]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
int sprintf(char *<[str]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
int asprintf(char **<[strp]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
int snprintf(char *<[str]>, size_t <[size]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdio.h>
|
||||
|
||||
int printf(<[format]> [, <[arg]>, ...])
|
||||
char *<[format]>;
|
||||
|
||||
int fprintf(<[fd]>, <[format]> [, <[arg]>, ...]);
|
||||
FILE *<[fd]>;
|
||||
char *<[format]>;
|
||||
|
||||
int asprintf(<[strp]>, <[format]> [, <[arg]>, ...]);
|
||||
char **<[strp]>;
|
||||
char *<[format]>;
|
||||
|
||||
int sprintf(<[str]>, <[format]> [, <[arg]>, ...]);
|
||||
char *<[str]>;
|
||||
char *<[format]>;
|
||||
|
||||
int snprintf(<[str]>, size_t <[size]>, <[format]> [, <[arg]>, ...]);
|
||||
char *<[str]>;
|
||||
size_t <[size]>;
|
||||
char *<[format]>;
|
||||
|
||||
DESCRIPTION
|
||||
<<printf>> accepts a series of arguments, applies to each a
|
||||
format specifier from <<*<[format]>>>, and writes the
|
||||
formatted data to <<stdout>>, terminated with a null character.
|
||||
The behavior of <<printf>> is undefined if there are not enough
|
||||
arguments for the format.
|
||||
<<printf>> returns when it reaches the end of the format string.
|
||||
If there are more arguments than the format requires, excess
|
||||
arguments are ignored.
|
||||
|
||||
<<fprintf>>, <<asprintf>>, <<sprintf>> and <<snprintf>> are identical
|
||||
to <<printf>>, other than the destination of the formatted output:
|
||||
<<fprintf>> sends the output to a specified file <[fd]>, while
|
||||
<<asprintf>> stores the output in a dynamically allocated buffer,
|
||||
while <<sprintf>> stores the output in the specified char array
|
||||
<[str]> and <<snprintf>> limits number of characters written to
|
||||
<[str]> to at most <[size]> (including terminating <<0>>). For
|
||||
<<sprintf>> and <<snprintf>>, the behavior is undefined if the
|
||||
output <<*<[str]>>> overlaps with one of the arguments. For
|
||||
<<asprintf>>, <[strp]> points to a pointer to char which is filled
|
||||
in with the dynamically allocated buffer. <[format]> is a pointer
|
||||
to a charater string containing two types of objects: ordinary
|
||||
characters (other than <<%>>), which are copied unchanged to the
|
||||
output, and conversion specifications, each of which is introduced
|
||||
by <<%>>. (To include <<%>> in the output, use <<%%>> in the format
|
||||
string.) A conversion specification has the following form:
|
||||
|
||||
. %[<[flags]>][<[width]>][.<[prec]>][<[size]>][<[type]>]
|
||||
|
||||
The fields of the conversion specification have the following meanings:
|
||||
|
||||
O+
|
||||
o <[flags]>
|
||||
|
||||
an optional sequence of characters which control
|
||||
output justification, numeric signs, decimal points,
|
||||
trailing zeroes, and octal and hex prefixes.
|
||||
The flag characters are minus (<<->>), plus (<<+>>),
|
||||
space ( ), zero (<<0>>), and sharp (<<#>>). They can
|
||||
appear in any combination.
|
||||
|
||||
o+
|
||||
o -
|
||||
The result of the conversion is left justified, and the right is
|
||||
padded with blanks. If you do not use this flag, the result is right
|
||||
justified, and padded on the left.
|
||||
|
||||
o +
|
||||
The result of a signed conversion (as determined by <[type]>)
|
||||
will always begin with a plus or minus sign. (If you do not use
|
||||
this flag, positive values do not begin with a plus sign.)
|
||||
|
||||
o " " (space)
|
||||
If the first character of a signed conversion specification
|
||||
is not a sign, or if a signed conversion results in no
|
||||
characters, the result will begin with a space. If the
|
||||
space ( ) flag and the plus (<<+>>) flag both appear,
|
||||
the space flag is ignored.
|
||||
|
||||
o 0
|
||||
If the <[type]> character is <<d>>, <<i>>, <<o>>, <<u>>,
|
||||
<<x>>, <<X>>, <<e>>, <<E>>, <<f>>, <<g>>, or <<G>>: leading zeroes,
|
||||
are used to pad the field width (following any indication of sign or
|
||||
base); no spaces are used for padding. If the zero (<<0>>) and
|
||||
minus (<<->>) flags both appear, the zero (<<0>>) flag will
|
||||
be ignored. For <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, and <<X>>
|
||||
conversions, if a precision <[prec]> is specified, the zero (<<0>>)
|
||||
flag is ignored.
|
||||
|
||||
Note that <<0>> is interpreted as a flag, not as the beginning
|
||||
of a field width.
|
||||
|
||||
o #
|
||||
The result is to be converted to an alternative form, according
|
||||
to the next character:
|
||||
|
||||
o+
|
||||
o 0
|
||||
increases precision to force the first digit
|
||||
of the result to be a zero.
|
||||
|
||||
o x
|
||||
a non-zero result will have a <<0x>> prefix.
|
||||
|
||||
o X
|
||||
a non-zero result will have a <<0X>> prefix.
|
||||
|
||||
o e, E or f
|
||||
The result will always contain a decimal point
|
||||
even if no digits follow the point.
|
||||
(Normally, a decimal point appears only if a
|
||||
digit follows it.) Trailing zeroes are removed.
|
||||
|
||||
o g or G
|
||||
same as <<e>> or <<E>>, but trailing zeroes
|
||||
are not removed.
|
||||
|
||||
o all others
|
||||
undefined.
|
||||
|
||||
o-
|
||||
o-
|
||||
|
||||
o <[width]>
|
||||
|
||||
<[width]> is an optional minimum field width. You can either
|
||||
specify it directly as a decimal integer, or indirectly by
|
||||
using instead an asterisk (<<*>>), in which case an <<int>>
|
||||
argument is used as the field width. Negative field widths
|
||||
are not supported; if you attempt to specify a negative field
|
||||
width, it is interpreted as a minus (<<->>) flag followed by a
|
||||
positive field width.
|
||||
|
||||
o <[prec]>
|
||||
|
||||
an optional field; if present, it is introduced with `<<.>>'
|
||||
(a period). This field gives the maximum number of
|
||||
characters to print in a conversion; the minimum number of
|
||||
digits of an integer to print, for conversions with <[type]>
|
||||
<<d>>, <<i>>, <<o>>, <<u>>, <<x>>, and <<X>>; the maximum number of
|
||||
significant digits, for the <<g>> and <<G>> conversions;
|
||||
or the number of digits to print after the decimal
|
||||
point, for <<e>>, <<E>>, and <<f>> conversions. You can specify
|
||||
the precision either directly as a decimal integer or
|
||||
indirectly by using an asterisk (<<*>>), in which case
|
||||
an <<int>> argument is used as the precision. Supplying a negative
|
||||
precision is equivalent to omitting the precision.
|
||||
If only a period is specified the precision is zero.
|
||||
If a precision appears with any other conversion <[type]>
|
||||
than those listed here, the behavior is undefined.
|
||||
|
||||
o <[size]>
|
||||
|
||||
<<h>>, <<l>>, and <<L>> are optional size characters which
|
||||
override the default way that <<printf>> interprets the
|
||||
data type of the corresponding argument. <<h>> forces
|
||||
the following <<d>>, <<i>>, <<o>>, <<u>>, <<x>> or <<X>> conversion
|
||||
<[type]> to apply to a <<short>> or <<unsigned short>>. <<h>> also
|
||||
forces a following <<n>> <[type]> to apply to
|
||||
a pointer to a <<short>>. Similarily, an
|
||||
<<l>> forces the following <<d>>, <<i>>, <<o>>, <<u>>,
|
||||
<<x>> or <<X>> conversion <[type]> to apply to a <<long>> or
|
||||
<<unsigned long>>. <<l>> also forces a following <<n>> <[type]> to
|
||||
apply to a pointer to a <<long>>. <<l>> with <<c>>, <<s>> is
|
||||
equivalent to <<C>>, <<S>> respectively. If an <<h>>
|
||||
or an <<l>> appears with another conversion
|
||||
specifier, the behavior is undefined. <<L>> forces a
|
||||
following <<e>>, <<E>>, <<f>>, <<g>> or <<G>> conversion <[type]> to
|
||||
apply to a <<long double>> argument. If <<L>> appears with
|
||||
any other conversion <[type]>, the behavior is undefined.
|
||||
|
||||
o <[type]>
|
||||
|
||||
<[type]> specifies what kind of conversion <<printf>> performs.
|
||||
Here is a table of these:
|
||||
|
||||
o+
|
||||
o %
|
||||
prints the percent character (<<%>>)
|
||||
|
||||
o c
|
||||
prints <[arg]> as single character
|
||||
|
||||
o C
|
||||
prints wchar_t <[arg]> as single multibyte character
|
||||
|
||||
o s
|
||||
prints characters until precision is reached or a null terminator
|
||||
is encountered; takes a string pointer
|
||||
|
||||
o S
|
||||
converts wchar_t characters to multibyte output characters until
|
||||
precision is reached or a null wchar_t terminator
|
||||
is encountered; takes a wchar_t pointer
|
||||
|
||||
o d
|
||||
prints a signed decimal integer; takes an <<int>> (same as <<i>>)
|
||||
|
||||
o i
|
||||
prints a signed decimal integer; takes an <<int>> (same as <<d>>)
|
||||
|
||||
o o
|
||||
prints a signed octal integer; takes an <<int>>
|
||||
|
||||
o u
|
||||
prints an unsigned decimal integer; takes an <<int>>
|
||||
|
||||
o x
|
||||
prints an unsigned hexadecimal integer (using <<abcdef>> as
|
||||
digits beyond <<9>>); takes an <<int>>
|
||||
|
||||
o X
|
||||
prints an unsigned hexadecimal integer (using <<ABCDEF>> as
|
||||
digits beyond <<9>>); takes an <<int>>
|
||||
|
||||
o f
|
||||
prints a signed value of the form <<[-]9999.9999>>; takes
|
||||
a floating-point number
|
||||
|
||||
o e
|
||||
prints a signed value of the form <<[-]9.9999e[+|-]999>>; takes a
|
||||
floating-point number
|
||||
|
||||
o E
|
||||
prints the same way as <<e>>, but using <<E>> to introduce the
|
||||
exponent; takes a floating-point number
|
||||
|
||||
o g
|
||||
prints a signed value in either <<f>> or <<e>> form, based on given
|
||||
value and precision---trailing zeros and the decimal point are
|
||||
printed only if necessary; takes a floating-point number
|
||||
|
||||
o G
|
||||
prints the same way as <<g>>, but using <<E>> for the exponent if an
|
||||
exponent is needed; takes a floating-point number
|
||||
|
||||
o n
|
||||
stores (in the same object) a count of the characters written;
|
||||
takes a pointer to <<int>>
|
||||
|
||||
o p
|
||||
prints a pointer in an implementation-defined format.
|
||||
This implementation treats the pointer as an
|
||||
<<unsigned long>> (same as <<Lu>>).
|
||||
o-
|
||||
O-
|
||||
|
||||
|
||||
RETURNS
|
||||
<<sprintf>> and <<asprintf>> return the number of bytes in the output string,
|
||||
save that the concluding <<NULL>> is not counted.
|
||||
<<printf>> and <<fprintf>> return the number of characters transmitted.
|
||||
If an error occurs, <<printf>> and <<fprintf>> return <<EOF>> and
|
||||
<<asprintf>> returns -1. No error returns occur for <<sprintf>>.
|
||||
|
||||
PORTABILITY
|
||||
The ANSI C standard specifies that implementations must
|
||||
support at least formatted output of up to 509 characters.
|
||||
|
||||
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
||||
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef _HAVE_STDC
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <_ansi.h>
|
||||
|
||||
#ifndef _SMALL_PRINTF
|
||||
#include "local.h"
|
||||
#else
|
||||
#ifdef INTEGER_ONLY
|
||||
#define _vfprintf_r _vfiprintf_r
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef _SMALL_PRINTF
|
||||
int
|
||||
#ifdef _HAVE_STDC
|
||||
_DEFUN (_sprintf_r, (ptr, str, fmt), struct _reent *ptr _AND char *str _AND _CONST char *fmt _DOTS)
|
||||
#else
|
||||
_sprintf_r (ptr, str, fmt, va_alist)
|
||||
struct _reent *ptr;
|
||||
char *str;
|
||||
_CONST char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
FILE f;
|
||||
|
||||
f._flags = __SWR | __SSTR;
|
||||
f._bf._base = f._p = (unsigned char *) str;
|
||||
f._bf._size = f._w = INT_MAX;
|
||||
f._file = -1; /* No file. */
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = _vfprintf_r (ptr, &f, fmt, ap);
|
||||
va_end (ap);
|
||||
*f._p = 0;
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
int
|
||||
#ifdef _HAVE_STDC
|
||||
_DEFUN (sprintf, (str, fmt), char *str _AND _CONST char *fmt _DOTS)
|
||||
#else
|
||||
sprintf (str, fmt, va_alist)
|
||||
char *str;
|
||||
_CONST char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
FILE f;
|
||||
|
||||
f._flags = __SWR | __SSTR;
|
||||
f._bf._base = f._p = (unsigned char *) str;
|
||||
f._bf._size = f._w = INT_MAX;
|
||||
f._file = -1; /* No file. */
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = _vfprintf_r (_REENT, &f, fmt, ap);
|
||||
va_end (ap);
|
||||
*f._p = 0;
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
1780
cpu/stm32w108/e_stdio/src/_SP_vfprintf.c
Normal file
1780
cpu/stm32w108/e_stdio/src/_SP_vfprintf.c
Normal file
File diff suppressed because it is too large
Load diff
32
cpu/stm32w108/e_stdio/src/floatio.h
Normal file
32
cpu/stm32w108/e_stdio/src/floatio.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* %W% (Berkeley) %G%
|
||||
*/
|
||||
|
||||
/*
|
||||
* Floating point scanf/printf (input/output) definitions.
|
||||
*/
|
||||
|
||||
#ifdef _NO_LONGDBL
|
||||
/* 11-bit exponent (VAX G floating point) is 308 decimal digits */
|
||||
#define MAXEXP 308
|
||||
#else /* !_NO_LONGDBL */
|
||||
/* 15-bit exponent (Intel extended floating point) is 4932 decimal digits */
|
||||
#define MAXEXP 4932
|
||||
#endif /* !_NO_LONGDBL */
|
||||
/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */
|
||||
#define MAXFRACT 39
|
38
cpu/stm32w108/e_stdio/src/fvwrite.h
Normal file
38
cpu/stm32w108/e_stdio/src/fvwrite.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
/* %W% (Berkeley) %G% */
|
||||
#include <_ansi.h>
|
||||
|
||||
/*
|
||||
* I/O descriptors for __sfvwrite().
|
||||
*/
|
||||
struct __siov {
|
||||
_CONST _PTR iov_base;
|
||||
size_t iov_len;
|
||||
};
|
||||
struct __suio {
|
||||
struct __siov *uio_iov;
|
||||
int uio_iovcnt;
|
||||
int uio_resid;
|
||||
};
|
||||
|
||||
|
||||
extern int _EXFUN(__sfvwrite,(FILE *, struct __suio *));
|
||||
extern int _EXFUN(__swsetup,(FILE *));
|
||||
|
||||
|
89
cpu/stm32w108/e_stdio/src/local.h
Normal file
89
cpu/stm32w108/e_stdio/src/local.h
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* %W% (UofMD/Berkeley) %G%
|
||||
*/
|
||||
|
||||
/*
|
||||
* Information local to this implementation of stdio,
|
||||
* in particular, macros and private variables.
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stdarg.h>
|
||||
#include <reent.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern int _EXFUN(__svfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
|
||||
extern FILE *_EXFUN(__sfp,(struct _reent *));
|
||||
extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*));
|
||||
extern int _EXFUN(__srefill,(FILE *));
|
||||
extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(void *, char *, int));
|
||||
extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite,(void *, char const *, int));
|
||||
extern _fpos_t _EXFUN(__sseek,(void *, _fpos_t, int));
|
||||
extern int _EXFUN(__sclose,(void *));
|
||||
extern int _EXFUN(__stextmode,(int));
|
||||
extern void _EXFUN(__sinit,(struct _reent *));
|
||||
extern void _EXFUN(_cleanup_r,(struct _reent *));
|
||||
extern void _EXFUN(__smakebuf,(FILE *));
|
||||
extern int _EXFUN(_fwalk,(struct _reent *, int (*)(FILE *)));
|
||||
struct _glue * _EXFUN(__sfmoreglue,(struct _reent *,int n));
|
||||
extern int _EXFUN(__srefill,(FILE *fp));
|
||||
|
||||
/* Called by the main entry point fns to ensure stdio has been initialized. */
|
||||
|
||||
#define CHECK_INIT(fp) \
|
||||
do \
|
||||
{ \
|
||||
if (!_REENT->__sdidinit) \
|
||||
__sinit (_REENT); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/* Return true iff the given FILE cannot be written now. */
|
||||
|
||||
#define cantwrite(fp) \
|
||||
((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \
|
||||
__swsetup(fp))
|
||||
|
||||
/* Test whether the given stdio file has an active ungetc buffer;
|
||||
release such a buffer, without restoring ordinary unread data. */
|
||||
|
||||
#define HASUB(fp) ((fp)->_ub._base != NULL)
|
||||
#define FREEUB(fp) { \
|
||||
if ((fp)->_ub._base != (fp)->_ubuf) \
|
||||
_free_r(_REENT, (char *)(fp)->_ub._base); \
|
||||
(fp)->_ub._base = NULL; \
|
||||
}
|
||||
|
||||
/* Test for an fgetline() buffer. */
|
||||
|
||||
#define HASLB(fp) ((fp)->_lb._base != NULL)
|
||||
#define FREELB(fp) { _free_r(_REENT,(char *)(fp)->_lb._base); (fp)->_lb._base = NULL; }
|
||||
|
||||
/* WARNING: _dcvt is defined in the stdlib directory, not here! */
|
||||
|
||||
char *_EXFUN(_dcvt,(struct _reent *, char *, double, int, int, char, int));
|
||||
char *_EXFUN(_sicvt,(char *, short, char));
|
||||
char *_EXFUN(_icvt,(char *, int, char));
|
||||
char *_EXFUN(_licvt,(char *, long, char));
|
||||
#ifdef __GNUC__
|
||||
char *_EXFUN(_llicvt,(char *, long long, char));
|
||||
#endif
|
||||
|
||||
#define CVT_BUF_SIZE 128
|
||||
|
||||
#define NDYNAMIC 4 /* add four more whenever necessary */
|
20
cpu/stm32w108/e_stdio/src/mbctype.h
Normal file
20
cpu/stm32w108/e_stdio/src/mbctype.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef _MBCTYPE_H_
|
||||
|
||||
#define _MBCTYPE_H_
|
||||
|
||||
/* escape character used for JIS encoding */
|
||||
#define ESC_CHAR 0x1b
|
||||
|
||||
/* functions used to support SHIFT_JIS, EUC-JP, and JIS multibyte encodings */
|
||||
|
||||
int _EXFUN(_issjis1, (int c));
|
||||
int _EXFUN(_issjis2, (int c));
|
||||
int _EXFUN(_iseucjp, (int c));
|
||||
int _EXFUN(_isjis, (int c));
|
||||
|
||||
#define _issjis1(c) (((c) >= 0x81 && (c) <= 0x9f) || ((c) >= 0xe0 && (c) <= 0xef))
|
||||
#define _issjis2(c) (((c) >= 0x40 && (c) <= 0x7e) || ((c) >= 0x80 && (c) <= 0xfc))
|
||||
#define _iseucjp(c) ((c) >= 0xa1 && (c) <= 0xfe)
|
||||
#define _isjis(c) ((c) >= 0x21 && (c) <= 0x7e)
|
||||
|
||||
#endif /* _MBCTYPE_H_ */
|
79
cpu/stm32w108/e_stdio/src/scanf.c
Normal file
79
cpu/stm32w108/e_stdio/src/scanf.c
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stdio.h>
|
||||
#include "local.h"
|
||||
|
||||
#ifdef _HAVE_STDC
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
int
|
||||
#ifdef _HAVE_STDC
|
||||
scanf (const char *fmt, ...)
|
||||
#else
|
||||
scanf (fmt, va_alist)
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
//_REENT_SMALL_CHECK_INIT(_stdin_r (_REENT));
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = __svfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
|
||||
va_end (ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* !_REENT_ONLY */
|
||||
|
||||
int
|
||||
#ifdef _HAVE_STDC
|
||||
_scanf_r (struct _reent *ptr, const char *fmt, ...)
|
||||
#else
|
||||
_scanf_r (ptr, fmt, va_alist)
|
||||
struct _reent *ptr;
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
//_REENT_SMALL_CHECK_INIT(_stdin_r (ptr));
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = __svfscanf_r (ptr, _stdin_r (ptr), fmt, ap);
|
||||
va_end (ap);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
1174
cpu/stm32w108/e_stdio/src/small_dtoa.c
Normal file
1174
cpu/stm32w108/e_stdio/src/small_dtoa.c
Normal file
File diff suppressed because it is too large
Load diff
1963
cpu/stm32w108/e_stdio/src/small_mprec.c
Normal file
1963
cpu/stm32w108/e_stdio/src/small_mprec.c
Normal file
File diff suppressed because it is too large
Load diff
383
cpu/stm32w108/e_stdio/src/small_mprec.h
Normal file
383
cpu/stm32w108/e_stdio/src/small_mprec.h
Normal file
|
@ -0,0 +1,383 @@
|
|||
/****************************************************************
|
||||
*
|
||||
* The author of this software is David M. Gay.
|
||||
*
|
||||
* Copyright (c) 1991 by AT&T.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose without fee is hereby granted, provided that this entire notice
|
||||
* is included in all copies of any software which is or includes a copy
|
||||
* or modification of this software and in all copies of the supporting
|
||||
* documentation for such software.
|
||||
*
|
||||
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
|
||||
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY
|
||||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
||||
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
||||
*
|
||||
***************************************************************/
|
||||
|
||||
/* Please send bug reports to
|
||||
David M. Gay
|
||||
AT&T Bell Laboratories, Room 2C-463
|
||||
600 Mountain Avenue
|
||||
Murray Hill, NJ 07974-2070
|
||||
U.S.A.
|
||||
dmg@research.att.com or research!dmg
|
||||
*/
|
||||
|
||||
|
||||
#include <ieeefp.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <errno.h>
|
||||
#include <sys/config.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __IEEE_LITTLE_ENDIAN
|
||||
#define IEEE_8087
|
||||
#endif
|
||||
|
||||
#ifdef __IEEE_BIG_ENDIAN
|
||||
#define IEEE_MC68k
|
||||
#endif
|
||||
|
||||
#ifdef __Z8000__
|
||||
#define Just_16
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
#include "stdio.h"
|
||||
#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
|
||||
#endif
|
||||
|
||||
#ifdef Unsigned_Shifts
|
||||
#define Sign_Extend(a,b) if (b < 0) a |= (__uint32_t)0xffff0000;
|
||||
#else
|
||||
#define Sign_Extend(a,b) /*no-op*/
|
||||
#endif
|
||||
|
||||
#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
|
||||
Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
|
||||
#endif
|
||||
|
||||
/* If we are going to examine or modify specific bits in a double using
|
||||
the word0 and/or word1 macros, then we must wrap the double inside
|
||||
a union. This is necessary to avoid undefined behavior according to
|
||||
the ANSI C spec. */
|
||||
union double_union
|
||||
{
|
||||
double d;
|
||||
__uint32_t i[2];
|
||||
};
|
||||
|
||||
#ifdef IEEE_8087
|
||||
#define word0(x) (x.i[1])
|
||||
#define word1(x) (x.i[0])
|
||||
#else
|
||||
#define word0(x) (x.i[0])
|
||||
#define word1(x) (x.i[1])
|
||||
#endif
|
||||
|
||||
/* The following definition of Storeinc is appropriate for MIPS processors.
|
||||
* An alternative that might be better on some machines is
|
||||
* #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
|
||||
*/
|
||||
#if defined (__IEEE_BYTES_LITTLE_ENDIAN) + defined (IEEE_8087) + defined (VAX)
|
||||
#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \
|
||||
((unsigned short *)a)[0] = (unsigned short)c, a++)
|
||||
#else
|
||||
#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \
|
||||
((unsigned short *)a)[1] = (unsigned short)c, a++)
|
||||
#endif
|
||||
|
||||
/* #define P DBL_MANT_DIG */
|
||||
/* Ten_pmax = floor(P*log(2)/log(5)) */
|
||||
/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
|
||||
/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
|
||||
/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
|
||||
|
||||
#if defined(IEEE_8087) + defined(IEEE_MC68k)
|
||||
#if defined (_DOUBLE_IS_32BITS)
|
||||
#define Exp_shift 23
|
||||
#define Exp_shift1 23
|
||||
#define Exp_msk1 ((__uint32_t)0x00800000L)
|
||||
#define Exp_msk11 ((__uint32_t)0x00800000L)
|
||||
#define Exp_mask ((__uint32_t)0x7f800000L)
|
||||
#define P 24
|
||||
#define Bias 127
|
||||
#if 0
|
||||
#define IEEE_Arith /* it is, but the code doesn't handle IEEE singles yet */
|
||||
#endif
|
||||
#define Emin (-126)
|
||||
#define Exp_1 ((__uint32_t)0x3f800000L)
|
||||
#define Exp_11 ((__uint32_t)0x3f800000L)
|
||||
#define Ebits 8
|
||||
#define Frac_mask ((__uint32_t)0x007fffffL)
|
||||
#define Frac_mask1 ((__uint32_t)0x007fffffL)
|
||||
#define Ten_pmax 10
|
||||
#define Sign_bit ((__uint32_t)0x80000000L)
|
||||
#define Ten_pmax 10
|
||||
#define Bletch 2
|
||||
#define Bndry_mask ((__uint32_t)0x007fffffL)
|
||||
#define Bndry_mask1 ((__uint32_t)0x007fffffL)
|
||||
#define LSB 1
|
||||
#define Sign_bit ((__uint32_t)0x80000000L)
|
||||
#define Log2P 1
|
||||
#define Tiny0 0
|
||||
#define Tiny1 1
|
||||
#define Quick_max 5
|
||||
#define Int_max 6
|
||||
#define Infinite(x) (word0(x) == ((__uint32_t)0x7f800000L))
|
||||
#undef word0
|
||||
#undef word1
|
||||
|
||||
#define word0(x) (x.i[0])
|
||||
#define word1(x) 0
|
||||
#else
|
||||
|
||||
#define Exp_shift 20
|
||||
#define Exp_shift1 20
|
||||
#define Exp_msk1 ((__uint32_t)0x100000L)
|
||||
#define Exp_msk11 ((__uint32_t)0x100000L)
|
||||
#define Exp_mask ((__uint32_t)0x7ff00000L)
|
||||
#define P 53
|
||||
#define Bias 1023
|
||||
#define IEEE_Arith
|
||||
#define Emin (-1022)
|
||||
#define Exp_1 ((__uint32_t)0x3ff00000L)
|
||||
#define Exp_11 ((__uint32_t)0x3ff00000L)
|
||||
#define Ebits 11
|
||||
#define Frac_mask ((__uint32_t)0xfffffL)
|
||||
#define Frac_mask1 ((__uint32_t)0xfffffL)
|
||||
#define Ten_pmax 22
|
||||
#define Bletch 0x10
|
||||
#define Bndry_mask ((__uint32_t)0xfffffL)
|
||||
#define Bndry_mask1 ((__uint32_t)0xfffffL)
|
||||
#define LSB 1
|
||||
#define Sign_bit ((__uint32_t)0x80000000L)
|
||||
#define Log2P 1
|
||||
#define Tiny0 0
|
||||
#define Tiny1 1
|
||||
#define Quick_max 14
|
||||
#define Int_max 14
|
||||
#define Infinite(x) (word0(x) == ((__uint32_t)0x7ff00000L)) /* sufficient test for here */
|
||||
#endif
|
||||
|
||||
#else
|
||||
#undef Sudden_Underflow
|
||||
#define Sudden_Underflow
|
||||
#ifdef IBM
|
||||
#define Exp_shift 24
|
||||
#define Exp_shift1 24
|
||||
#define Exp_msk1 ((__uint32_t)0x1000000L)
|
||||
#define Exp_msk11 ((__uint32_t)0x1000000L)
|
||||
#define Exp_mask ((__uint32_t)0x7f000000L)
|
||||
#define P 14
|
||||
#define Bias 65
|
||||
#define Exp_1 ((__uint32_t)0x41000000L)
|
||||
#define Exp_11 ((__uint32_t)0x41000000L)
|
||||
#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */
|
||||
#define Frac_mask ((__uint32_t)0xffffffL)
|
||||
#define Frac_mask1 ((__uint32_t)0xffffffL)
|
||||
#define Bletch 4
|
||||
#define Ten_pmax 22
|
||||
#define Bndry_mask ((__uint32_t)0xefffffL)
|
||||
#define Bndry_mask1 ((__uint32_t)0xffffffL)
|
||||
#define LSB 1
|
||||
#define Sign_bit ((__uint32_t)0x80000000L)
|
||||
#define Log2P 4
|
||||
#define Tiny0 ((__uint32_t)0x100000L)
|
||||
#define Tiny1 0
|
||||
#define Quick_max 14
|
||||
#define Int_max 15
|
||||
#else /* VAX */
|
||||
#define Exp_shift 23
|
||||
#define Exp_shift1 7
|
||||
#define Exp_msk1 0x80
|
||||
#define Exp_msk11 ((__uint32_t)0x800000L)
|
||||
#define Exp_mask ((__uint32_t)0x7f80L)
|
||||
#define P 56
|
||||
#define Bias 129
|
||||
#define Exp_1 ((__uint32_t)0x40800000L)
|
||||
#define Exp_11 ((__uint32_t)0x4080L)
|
||||
#define Ebits 8
|
||||
#define Frac_mask ((__uint32_t)0x7fffffL)
|
||||
#define Frac_mask1 ((__uint32_t)0xffff007fL)
|
||||
#define Ten_pmax 24
|
||||
#define Bletch 2
|
||||
#define Bndry_mask ((__uint32_t)0xffff007fL)
|
||||
#define Bndry_mask1 ((__uint32_t)0xffff007fL)
|
||||
#define LSB ((__uint32_t)0x10000L)
|
||||
#define Sign_bit ((__uint32_t)0x8000L)
|
||||
#define Log2P 1
|
||||
#define Tiny0 0x80
|
||||
#define Tiny1 0
|
||||
#define Quick_max 15
|
||||
#define Int_max 15
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef IEEE_Arith
|
||||
#define ROUND_BIASED
|
||||
#endif
|
||||
|
||||
#ifdef RND_PRODQUOT
|
||||
#define rounded_product(a,b) a = rnd_prod(a, b)
|
||||
#define rounded_quotient(a,b) a = rnd_quot(a, b)
|
||||
#ifdef KR_headers
|
||||
extern double rnd_prod(), rnd_quot();
|
||||
#else
|
||||
extern double rnd_prod(double, double), rnd_quot(double, double);
|
||||
#endif
|
||||
#else
|
||||
#define rounded_product(a,b) a *= b
|
||||
#define rounded_quotient(a,b) a /= b
|
||||
#endif
|
||||
|
||||
#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
|
||||
#define Big1 ((__uint32_t)0xffffffffL)
|
||||
|
||||
#ifndef Just_16
|
||||
/* When Pack_32 is not defined, we store 16 bits per 32-bit long.
|
||||
* This makes some inner loops simpler and sometimes saves work
|
||||
* during multiplications, but it often seems to make things slightly
|
||||
* slower. Hence the default is now to store 32 bits per long.
|
||||
*/
|
||||
|
||||
#ifndef Pack_32
|
||||
#define Pack_32
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" double strtod(const char *s00, char **se);
|
||||
extern "C" char *dtoa(double d, int mode, int ndigits,
|
||||
int *decpt, int *sign, char **rve);
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct _Bigint _Bigint;
|
||||
|
||||
#if (defined (_SMALL_PRINTF) || defined(SMALL_SCANF) )
|
||||
#define SMALL_LIB
|
||||
#endif
|
||||
|
||||
#ifdef SMALL_LIB
|
||||
|
||||
|
||||
|
||||
|
||||
#define small_Balloc _small_Balloc
|
||||
#define small_Bfree _small_Bfree
|
||||
#define small_multadd _small_multadd
|
||||
#define small_s2b _small_s2b
|
||||
#define small_lo0bits _small_lo0bits
|
||||
#define small_hi0bits _small_hi0bits
|
||||
#define small_i2b _small_i2b
|
||||
#define small_mult _small_multiply
|
||||
#define small_pow5mult _small_pow5mult
|
||||
#define small_lshift _small_lshift
|
||||
#define small_cmp __small_mcmp
|
||||
#define small_diff __small_mdiff
|
||||
#define small_ulp _small_ulp
|
||||
#define small_b2d _small_b2d
|
||||
#define small_d2b _small_d2b
|
||||
#define small_ratio _small_ratio
|
||||
|
||||
#define small_tens __small_mprec_tens
|
||||
#define small_bigtens __small_mprec_bigtens
|
||||
#define small_tinytens __small_mprec_tinytens
|
||||
|
||||
struct _reent ;
|
||||
double _EXFUN(small_ulp,(double x));
|
||||
double _EXFUN(small_b2d,(_Bigint *a , int *e));
|
||||
_Bigint * _EXFUN(small_multadd,(struct _reent *p, _Bigint *, int, int,_Bigint tab[]));
|
||||
_Bigint * _EXFUN(small_s2b,(struct _reent *, const char*, int, int, __ULong,_Bigint tab[]));
|
||||
_Bigint * _EXFUN(small_i2b,(struct _reent *,int,_Bigint tab[]));
|
||||
_Bigint * _EXFUN(small_mult, (struct _reent *, _Bigint *, _Bigint *,_Bigint tab[]));
|
||||
_Bigint * _EXFUN(small_pow5mult, (struct _reent *, _Bigint *, int k,_Bigint tab[]));
|
||||
int _EXFUN(small_hi0bits,(__ULong));
|
||||
int _EXFUN(small_lo0bits,(__ULong *));
|
||||
_Bigint * _EXFUN(small_d2b,(struct _reent *p, double d, int *e, int *bits,_Bigint tab[]));
|
||||
_Bigint * _EXFUN(small_lshift,(struct _reent *p, _Bigint *b, int k,_Bigint tab[]));
|
||||
_Bigint * _EXFUN(small_diff,(struct _reent *p, _Bigint *a, _Bigint *b,_Bigint tab[]));
|
||||
int _EXFUN(small_cmp,(_Bigint *a, _Bigint *b));
|
||||
|
||||
double _EXFUN(small_ratio,(_Bigint *a, _Bigint *b));
|
||||
#define Bcopy(x,y) memcpy((char *)&x->_sign, (char *)&y->_sign, y->_wds*sizeof(__Long) + 2*sizeof(int))
|
||||
|
||||
#if defined(_DOUBLE_IS_32BITS) && defined(__v800)
|
||||
#define n_bigtens 2
|
||||
#else
|
||||
#define n_bigtens 5
|
||||
#endif
|
||||
|
||||
extern _CONST double small_tinytens[];
|
||||
extern _CONST double small_bigtens[];
|
||||
extern _CONST double small_tens[];
|
||||
|
||||
|
||||
double _EXFUN(_small_mprec_log10,(int));
|
||||
|
||||
|
||||
#else // NO SMALL_LIB
|
||||
|
||||
|
||||
|
||||
#define Balloc _Balloc
|
||||
#define Bfree _Bfree
|
||||
#define multadd _multadd
|
||||
#define s2b _s2b
|
||||
#define lo0bits _lo0bits
|
||||
#define hi0bits _hi0bits
|
||||
#define i2b _i2b
|
||||
#define mult _multiply
|
||||
#define pow5mult _pow5mult
|
||||
#define lshift _lshift
|
||||
#define cmp __mcmp
|
||||
#define diff __mdiff
|
||||
#define ulp _ulp
|
||||
#define b2d _b2d
|
||||
#define d2b _d2b
|
||||
#define ratio _ratio
|
||||
|
||||
#define tens __mprec_tens
|
||||
#define bigtens __mprec_bigtens
|
||||
#define tinytens __mprec_tinytens
|
||||
|
||||
struct _reent ;
|
||||
double _EXFUN(ulp,(double x));
|
||||
double _EXFUN(b2d,(_Bigint *a , int *e));
|
||||
_Bigint * _EXFUN(Balloc,(struct _reent *p, int k));
|
||||
void _EXFUN(Bfree,(struct _reent *p, _Bigint *v));
|
||||
_Bigint * _EXFUN(multadd,(struct _reent *p, _Bigint *, int, int));
|
||||
_Bigint * _EXFUN(s2b,(struct _reent *, const char*, int, int, __ULong));
|
||||
_Bigint * _EXFUN(i2b,(struct _reent *,int));
|
||||
_Bigint * _EXFUN(mult, (struct _reent *, _Bigint *, _Bigint *));
|
||||
_Bigint * _EXFUN(pow5mult, (struct _reent *, _Bigint *, int k));
|
||||
int _EXFUN(hi0bits,(__ULong));
|
||||
int _EXFUN(lo0bits,(__ULong *));
|
||||
_Bigint * _EXFUN(d2b,(struct _reent *p, double d, int *e, int *bits));
|
||||
_Bigint * _EXFUN(lshift,(struct _reent *p, _Bigint *b, int k));
|
||||
_Bigint * _EXFUN(diff,(struct _reent *p, _Bigint *a, _Bigint *b));
|
||||
int _EXFUN(cmp,(_Bigint *a, _Bigint *b));
|
||||
|
||||
double _EXFUN(ratio,(_Bigint *a, _Bigint *b));
|
||||
#define Bcopy(x,y) memcpy((char *)&x->_sign, (char *)&y->_sign, y->_wds*sizeof(__Long) + 2*sizeof(int))
|
||||
|
||||
#if defined(_DOUBLE_IS_32BITS) && defined(__v800)
|
||||
#define n_bigtens 2
|
||||
#else
|
||||
#define n_bigtens 5
|
||||
#endif
|
||||
|
||||
extern _CONST double tinytens[];
|
||||
extern _CONST double bigtens[];
|
||||
extern _CONST double tens[];
|
||||
|
||||
|
||||
double _EXFUN(_mprec_log10,(int));
|
||||
|
||||
#endif
|
936
cpu/stm32w108/e_stdio/src/small_strtod.c
Normal file
936
cpu/stm32w108/e_stdio/src/small_strtod.c
Normal file
|
@ -0,0 +1,936 @@
|
|||
/*
|
||||
FUNCTON
|
||||
<<strtod>>, <<strtof>>---string to double or float
|
||||
|
||||
INDEX
|
||||
strtod
|
||||
INDEX
|
||||
_strtod_r
|
||||
INDEX
|
||||
strtof
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
double strtod(const char *<[str]>, char **<[tail]>);
|
||||
float strtof(const char *<[str]>, char **<[tail]>);
|
||||
|
||||
double _strtod_r(void *<[reent]>,
|
||||
const char *<[str]>, char **<[tail]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
double strtod(<[str]>,<[tail]>)
|
||||
char *<[str]>;
|
||||
char **<[tail]>;
|
||||
|
||||
float strtof(<[str]>,<[tail]>)
|
||||
char *<[str]>;
|
||||
char **<[tail]>;
|
||||
|
||||
double _strtod_r(<[reent]>,<[str]>,<[tail]>)
|
||||
char *<[reent]>;
|
||||
char *<[str]>;
|
||||
char **<[tail]>;
|
||||
|
||||
DESCRIPTION
|
||||
The function <<strtod>> parses the character string <[str]>,
|
||||
producing a substring which can be converted to a double
|
||||
value. The substring converted is the longest initial
|
||||
subsequence of <[str]>, beginning with the first
|
||||
non-whitespace character, that has the format:
|
||||
.[+|-]<[digits]>[.][<[digits]>][(e|E)[+|-]<[digits]>]
|
||||
The substring contains no characters if <[str]> is empty, consists
|
||||
entirely of whitespace, or if the first non-whitespace
|
||||
character is something other than <<+>>, <<->>, <<.>>, or a
|
||||
digit. If the substring is empty, no conversion is done, and
|
||||
the value of <[str]> is stored in <<*<[tail]>>>. Otherwise,
|
||||
the substring is converted, and a pointer to the final string
|
||||
(which will contain at least the terminating null character of
|
||||
<[str]>) is stored in <<*<[tail]>>>. If you want no
|
||||
assignment to <<*<[tail]>>>, pass a null pointer as <[tail]>.
|
||||
<<strtof>> is identical to <<strtod>> except for its return type.
|
||||
|
||||
This implementation returns the nearest machine number to the
|
||||
input decimal string. Ties are broken by using the IEEE
|
||||
round-even rule.
|
||||
|
||||
The alternate function <<_strtod_r>> is a reentrant version.
|
||||
The extra argument <[reent]> is a pointer to a reentrancy structure.
|
||||
|
||||
RETURNS
|
||||
<<strtod>> returns the converted substring value, if any. If
|
||||
no conversion could be performed, 0 is returned. If the
|
||||
correct value is out of the range of representable values,
|
||||
plus or minus <<HUGE_VAL>> is returned, and <<ERANGE>> is
|
||||
stored in errno. If the correct value would cause underflow, 0
|
||||
is returned and <<ERANGE>> is stored in errno.
|
||||
|
||||
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
||||
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
|
||||
*/
|
||||
|
||||
/****************************************************************
|
||||
*
|
||||
* The author of this software is David M. Gay.
|
||||
*
|
||||
* Copyright (c) 1991 by AT&T.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose without fee is hereby granted, provided that this entire notice
|
||||
* is included in all copies of any software which is or includes a copy
|
||||
* or modification of this software and in all copies of the supporting
|
||||
* documentation for such software.
|
||||
*
|
||||
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
|
||||
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY
|
||||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
||||
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
||||
*
|
||||
***************************************************************/
|
||||
|
||||
/* Please send bug reports to
|
||||
David M. Gay
|
||||
AT&T Bell Laboratories, Room 2C-463
|
||||
600 Mountain Avenue
|
||||
Murray Hill, NJ 07974-2070
|
||||
U.S.A.
|
||||
dmg@research.att.com or research!dmg
|
||||
*/
|
||||
|
||||
|
||||
/* Scanf and printf call both the small_mprec.c file if small_scanf
|
||||
* has not been specfied optimizations concerning small_mprec.c and
|
||||
* call of balloc will be performed anyway for scanf.
|
||||
*/
|
||||
|
||||
#ifdef _SMALL_PRINTF
|
||||
#ifndef SMALL_SCANF
|
||||
#define SMALL_SCANF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <reent.h>
|
||||
#include <string.h>
|
||||
#include "small_mprec.h"
|
||||
|
||||
double
|
||||
_DEFUN (_strtod_r, (ptr, s00, se),
|
||||
struct _reent *ptr _AND
|
||||
_CONST char *s00 _AND
|
||||
char **se)
|
||||
{
|
||||
int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, e1, esign, i, j,
|
||||
k, nd, nd0, nf, nz, nz0, sign;
|
||||
long e;
|
||||
_CONST char *s, *s0, *s1;
|
||||
double aadj, aadj1, adj;
|
||||
long L;
|
||||
unsigned long z;
|
||||
__ULong y;
|
||||
union double_union rv, rv0;
|
||||
|
||||
_Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
|
||||
|
||||
#ifdef SMALL_SCANF
|
||||
|
||||
/*
|
||||
* For the SMALL_SCANF implementation for floating points numbers :
|
||||
* - To avoid the call of allocator we defined a buffer for each variable : instead of taking the adress
|
||||
* provided by Balloc variables are initialized to the beginning of the array.
|
||||
* - For some variables many buffers have been declared, in fact for each call of small_lshift we used a
|
||||
* buffer that has not been used at the moment
|
||||
* - This buffers are used in the call of function declared in small_mprec.h
|
||||
* To have more informations look at small_mprec.c
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#define BUF_SIZE 32
|
||||
#define BUF_LSHIFT_SIZE 40
|
||||
|
||||
_Bigint tab_bb[BUF_LSHIFT_SIZE],tab_bb1[BUF_SIZE],tab_bd[BUF_SIZE],tab_bd0[BUF_SIZE],tab_bs[BUF_LSHIFT_SIZE], tab_delta[BUF_LSHIFT_SIZE];
|
||||
_Bigint tab_bblshift[BUF_LSHIFT_SIZE],tab_bslshift[BUF_LSHIFT_SIZE], tab_deltalshift[BUF_LSHIFT_SIZE],tab_bdlshift[BUF_LSHIFT_SIZE];
|
||||
#endif
|
||||
|
||||
sign = nz0 = nz = 0;
|
||||
rv.d = 0.;
|
||||
for (s = s00;; s++)
|
||||
switch (*s)
|
||||
{
|
||||
case '-':
|
||||
sign = 1;
|
||||
/* no break */
|
||||
case '+':
|
||||
if (*++s)
|
||||
goto break2;
|
||||
/* no break */
|
||||
case 0:
|
||||
s = s00;
|
||||
goto ret;
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\v':
|
||||
case '\f':
|
||||
case '\r':
|
||||
case ' ':
|
||||
continue;
|
||||
default:
|
||||
goto break2;
|
||||
}
|
||||
break2:
|
||||
if (*s == '0')
|
||||
{
|
||||
nz0 = 1;
|
||||
while (*++s == '0');
|
||||
if (!*s)
|
||||
goto ret;
|
||||
}
|
||||
s0 = s;
|
||||
y = z = 0;
|
||||
for (nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
|
||||
if (nd < 9)
|
||||
y = 10 * y + c - '0';
|
||||
else if (nd < 16)
|
||||
z = 10 * z + c - '0';
|
||||
nd0 = nd;
|
||||
if (c == '.')
|
||||
{
|
||||
c = *++s;
|
||||
if (!nd)
|
||||
{
|
||||
for (; c == '0'; c = *++s)
|
||||
nz++;
|
||||
if (c > '0' && c <= '9')
|
||||
{
|
||||
s0 = s;
|
||||
nf += nz;
|
||||
nz = 0;
|
||||
goto have_dig;
|
||||
}
|
||||
goto dig_done;
|
||||
}
|
||||
for (; c >= '0' && c <= '9'; c = *++s)
|
||||
{
|
||||
have_dig:
|
||||
nz++;
|
||||
if (c -= '0')
|
||||
{
|
||||
nf += nz;
|
||||
for (i = 1; i < nz; i++)
|
||||
if (nd++ < 9)
|
||||
y *= 10;
|
||||
else if (nd <= DBL_DIG + 1)
|
||||
z *= 10;
|
||||
if (nd++ < 9)
|
||||
y = 10 * y + c;
|
||||
else if (nd <= DBL_DIG + 1)
|
||||
z = 10 * z + c;
|
||||
nz = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
dig_done:
|
||||
e = 0;
|
||||
if (c == 'e' || c == 'E')
|
||||
{
|
||||
if (!nd && !nz && !nz0)
|
||||
{
|
||||
s = s00;
|
||||
goto ret;
|
||||
}
|
||||
s00 = s;
|
||||
esign = 0;
|
||||
switch (c = *++s)
|
||||
{
|
||||
case '-':
|
||||
esign = 1;
|
||||
case '+':
|
||||
c = *++s;
|
||||
}
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
while (c == '0')
|
||||
c = *++s;
|
||||
if (c > '0' && c <= '9')
|
||||
{
|
||||
e = c - '0';
|
||||
s1 = s;
|
||||
while ((c = *++s) >= '0' && c <= '9')
|
||||
e = 10 * e + c - '0';
|
||||
if (s - s1 > 8)
|
||||
/* Avoid confusion from exponents
|
||||
* so large that e might overflow.
|
||||
*/
|
||||
e = 9999999L;
|
||||
if (esign)
|
||||
e = -e;
|
||||
}
|
||||
else
|
||||
e = 0;
|
||||
}
|
||||
else
|
||||
s = s00;
|
||||
}
|
||||
if (!nd)
|
||||
{
|
||||
if (!nz && !nz0)
|
||||
s = s00;
|
||||
goto ret;
|
||||
}
|
||||
e1 = e -= nf;
|
||||
|
||||
/* Now we have nd0 digits, starting at s0, followed by a
|
||||
* decimal point, followed by nd-nd0 digits. The number we're
|
||||
* after is the integer represented by those digits times
|
||||
* 10**e */
|
||||
|
||||
if (!nd0)
|
||||
nd0 = nd;
|
||||
k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
|
||||
rv.d = y;
|
||||
if (k > 9)
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d = tens[k - 9] * rv.d + z;
|
||||
#else
|
||||
rv.d = small_tens[k - 9] * rv.d + z;
|
||||
#endif
|
||||
bd0 = 0;
|
||||
if (nd <= DBL_DIG
|
||||
#ifndef RND_PRODQUOT
|
||||
&& FLT_ROUNDS == 1
|
||||
#endif
|
||||
)
|
||||
{
|
||||
if (!e)
|
||||
goto ret;
|
||||
if (e > 0)
|
||||
{
|
||||
if (e <= Ten_pmax)
|
||||
{
|
||||
#ifdef VAX
|
||||
goto vax_ovfl_check;
|
||||
#else
|
||||
#ifndef SMALL_SCANF
|
||||
/* rv.d = */ rounded_product (rv.d, tens[e]);
|
||||
#else
|
||||
rounded_product (rv.d, small_tens[e]);
|
||||
#endif
|
||||
goto ret;
|
||||
#endif
|
||||
}
|
||||
i = DBL_DIG - nd;
|
||||
if (e <= Ten_pmax + i)
|
||||
{
|
||||
/* A fancier test would sometimes let us do
|
||||
* this for larger i values.
|
||||
*/
|
||||
e -= i;
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d *= tens[i];
|
||||
#else
|
||||
rv.d *= small_tens[i];
|
||||
#endif
|
||||
#ifdef VAX
|
||||
/* VAX exponent range is so narrow we must
|
||||
* worry about overflow here...
|
||||
*/
|
||||
vax_ovfl_check:
|
||||
word0 (rv) -= P * Exp_msk1;
|
||||
#ifndef SMALL_SCANF
|
||||
/* rv.d = */ rounded_product (rv.d, tens[e]);
|
||||
#else
|
||||
/* rv.d = */ rounded_product (rv.d, small_tens[e]);
|
||||
#endif
|
||||
if ((word0 (rv) & Exp_mask)
|
||||
> Exp_msk1 * (DBL_MAX_EXP + Bias - 1 - P))
|
||||
goto ovfl;
|
||||
word0 (rv) += P * Exp_msk1;
|
||||
#else
|
||||
#ifndef SMALL_SCANF
|
||||
/* rv.d = */ rounded_product (rv.d, tens[e]);
|
||||
#else
|
||||
/* rv.d = */ rounded_product (rv.d, small_tens[e]);
|
||||
#endif
|
||||
#endif
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
#ifndef Inaccurate_Divide
|
||||
else if (e >= -Ten_pmax)
|
||||
{
|
||||
#ifndef SMALL_SCANF
|
||||
/* rv.d = */ rounded_quotient (rv.d, tens[-e]);
|
||||
#else
|
||||
/* rv.d = */ rounded_quotient (rv.d, small_tens[-e]);
|
||||
#endif
|
||||
goto ret;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
e1 += nd - k;
|
||||
|
||||
/* Get starting approximation = rv.d * 10**e1 */
|
||||
|
||||
if (e1 > 0)
|
||||
{
|
||||
if ((i = e1 & 15) != 0)
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d *= tens[i];
|
||||
#else
|
||||
rv.d *= small_tens[i];
|
||||
#endif
|
||||
if (e1 &= ~15)
|
||||
{
|
||||
if (e1 > DBL_MAX_10_EXP)
|
||||
{
|
||||
ovfl:
|
||||
ptr->_errno = ERANGE;
|
||||
#ifdef _HAVE_STDC
|
||||
rv.d = HUGE_VAL;
|
||||
#else
|
||||
/* Can't trust HUGE_VAL */
|
||||
#ifdef IEEE_Arith
|
||||
word0 (rv) = Exp_mask;
|
||||
#ifndef _DOUBLE_IS_32BITS
|
||||
word1 (rv) = 0;
|
||||
#endif
|
||||
#else
|
||||
word0 (rv) = Big0;
|
||||
#ifndef _DOUBLE_IS_32BITS
|
||||
word1 (rv) = Big1;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
if (bd0)
|
||||
goto retfree;
|
||||
goto ret;
|
||||
}
|
||||
if (e1 >>= 4)
|
||||
{
|
||||
for (j = 0; e1 > 1; j++, e1 >>= 1)
|
||||
if (e1 & 1)
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d *= bigtens[j];
|
||||
#else
|
||||
rv.d *= small_bigtens[j];
|
||||
#endif
|
||||
|
||||
/* The last multiplication could overflow. */
|
||||
word0 (rv) -= P * Exp_msk1;
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d *= bigtens[j];
|
||||
#else
|
||||
rv.d *= small_bigtens[j];
|
||||
#endif
|
||||
|
||||
if ((z = word0 (rv) & Exp_mask)
|
||||
> Exp_msk1 * (DBL_MAX_EXP + Bias - P))
|
||||
goto ovfl;
|
||||
if (z > Exp_msk1 * (DBL_MAX_EXP + Bias - 1 - P))
|
||||
{
|
||||
/* set to largest number */
|
||||
/* (Can't trust DBL_MAX) */
|
||||
word0 (rv) = Big0;
|
||||
#ifndef _DOUBLE_IS_32BITS
|
||||
word1 (rv) = Big1;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
word0 (rv) += P * Exp_msk1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if (e1 < 0)
|
||||
{
|
||||
e1 = -e1;
|
||||
if ((i = e1 & 15) != 0)
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d /= tens[i];
|
||||
#else
|
||||
rv.d /= small_tens[i];
|
||||
#endif
|
||||
if (e1 &= ~15)
|
||||
{
|
||||
e1 >>= 4;
|
||||
if (e1 >= 1 << n_bigtens)
|
||||
goto undfl;
|
||||
for (j = 0; e1 > 1; j++, e1 >>= 1)
|
||||
if (e1 & 1)
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d *= tinytens[j];
|
||||
/* The last multiplication could underflow. */
|
||||
rv0.d = rv.d;
|
||||
rv.d *=tinytens[j];
|
||||
#else
|
||||
rv.d *= small_tinytens[j];
|
||||
/* The last multiplication could underflow. */
|
||||
rv0.d = rv.d;
|
||||
rv.d *= small_tinytens[j];
|
||||
#endif
|
||||
if (!rv.d)
|
||||
{
|
||||
rv.d = 2. * rv0.d;
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d *= tinytens[j];
|
||||
#else
|
||||
rv.d *= small_tinytens[j];
|
||||
#endif
|
||||
if (!rv.d)
|
||||
{
|
||||
undfl:
|
||||
rv.d = 0.;
|
||||
ptr->_errno = ERANGE;
|
||||
if (bd0)
|
||||
goto retfree;
|
||||
goto ret;
|
||||
}
|
||||
#ifndef _DOUBLE_IS_32BITS
|
||||
word0 (rv) = Tiny0;
|
||||
word1 (rv) = Tiny1;
|
||||
#else
|
||||
word0 (rv) = Tiny1;
|
||||
#endif
|
||||
/* The refinement below will clean
|
||||
* this approximation up.
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Now the hard part -- adjusting rv to the correct value.*/
|
||||
|
||||
/* Put digits into bd: true value = bd * 10^e */
|
||||
#ifndef SMALL_SCANF
|
||||
bd0 = s2b (ptr, s0, nd0, nd, y);
|
||||
#else
|
||||
bd0 = small_s2b(ptr,s0, nd0, nd, y, &tab_bd0[0]);
|
||||
#endif
|
||||
|
||||
for (;;)
|
||||
{
|
||||
#ifndef SMALL_SCANF
|
||||
bd = Balloc (ptr, bd0->_k);
|
||||
#else
|
||||
bd = &tab_bd[0];
|
||||
bd->_k = bd0->_k;
|
||||
bd->_maxwds = 1 << (bd0->_k);
|
||||
bd->_sign = bd->_wds =0;
|
||||
|
||||
#endif
|
||||
Bcopy (bd, bd0);
|
||||
#ifndef SMALL_SCANF
|
||||
bb = d2b (ptr, rv.d, &bbe, &bbbits); /* rv.d = bb * 2^bbe */
|
||||
bs = i2b (ptr, 1);
|
||||
#else
|
||||
bb = small_d2b (ptr, rv.d, &bbe, &bbbits, &tab_bb[0]); /* rv.d = bb * 2^bbe */
|
||||
bs = small_i2b (ptr, 1, &tab_bs[0]);
|
||||
#endif
|
||||
if (e >= 0)
|
||||
{
|
||||
bb2 = bb5 = 0;
|
||||
bd2 = bd5 = e;
|
||||
}
|
||||
else
|
||||
{
|
||||
bb2 = bb5 = -e;
|
||||
bd2 = bd5 = 0;
|
||||
}
|
||||
if (bbe >= 0)
|
||||
bb2 += bbe;
|
||||
else
|
||||
bd2 -= bbe;
|
||||
bs2 = bb2;
|
||||
#ifdef Sudden_Underflow
|
||||
#ifdef IBM
|
||||
j = 1 + 4 * P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
|
||||
#else
|
||||
j = P + 1 - bbbits;
|
||||
#endif
|
||||
#else
|
||||
i = bbe + bbbits - 1; /* logb(rv.d) */
|
||||
if (i < Emin) /* denormal */
|
||||
j = bbe + (P - Emin);
|
||||
else
|
||||
j = P + 1 - bbbits;
|
||||
#endif
|
||||
bb2 += j;
|
||||
bd2 += j;
|
||||
i = bb2 < bd2 ? bb2 : bd2;
|
||||
if (i > bs2)
|
||||
i = bs2;
|
||||
if (i > 0)
|
||||
{
|
||||
bb2 -= i;
|
||||
bd2 -= i;
|
||||
bs2 -= i;
|
||||
}
|
||||
if (bb5 > 0)
|
||||
{
|
||||
#ifndef SMALL_SCANF
|
||||
bs = pow5mult (ptr, bs, bb5);
|
||||
bb1 = mult (ptr, bs, bb);
|
||||
Bfree (ptr, bb);
|
||||
bb = bb1;
|
||||
#else
|
||||
if (bs == &tab_bs[0]){
|
||||
bs = small_pow5mult (ptr, bs, bb5,&tab_bslshift[0]);
|
||||
}
|
||||
else{
|
||||
bs = small_pow5mult (ptr, bs, bb5,&tab_bs[0]);
|
||||
}
|
||||
bb1 = small_mult (ptr, bs, bb,&tab_bb1[0]);
|
||||
bb = bb1;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#ifndef SMALL_SCANF
|
||||
if (bb2 > 0)
|
||||
bb = lshift (ptr, bb, bb2);
|
||||
if (bd5 > 0)
|
||||
bd = pow5mult (ptr, bd, bd5);
|
||||
if (bd2 > 0)
|
||||
bd = lshift (ptr, bd, bd2);
|
||||
if (bs2 > 0)
|
||||
bs = lshift (ptr, bs, bs2);
|
||||
delta = diff (ptr, bb, bd);
|
||||
dsign = delta->_sign;
|
||||
delta->_sign = 0;
|
||||
i = cmp (delta, bs);
|
||||
#else
|
||||
if (bb2 > 0){
|
||||
if (bb == &tab_bb[0] ){
|
||||
bb = small_lshift (ptr, bb, bb2,&tab_bblshift[0]);
|
||||
}
|
||||
else {
|
||||
bb = small_lshift (ptr, bb, bb2,&tab_bblshift[0]);
|
||||
}
|
||||
}
|
||||
if (bd5 > 0){
|
||||
if (bd == &tab_bd[0]){
|
||||
bd = small_pow5mult (ptr, bd, bd5, &tab_bdlshift[0]);
|
||||
}
|
||||
else{
|
||||
bd = small_pow5mult (ptr, bd, bd5, &tab_bd[0]);
|
||||
}
|
||||
}
|
||||
if (bd2 > 0){
|
||||
if (bd == &tab_bd[0] ){
|
||||
bd = small_lshift (ptr, bb, bd2,&tab_bdlshift[0]);
|
||||
}
|
||||
else {
|
||||
bd = small_lshift (ptr, bd, bd2,&tab_bd[0]);
|
||||
}
|
||||
}
|
||||
if (bs2 > 0){
|
||||
if ( bs == &tab_bs[0] ){
|
||||
bs = small_lshift (ptr, bs, bs2,&tab_bslshift[0]);
|
||||
}
|
||||
else{
|
||||
bs = small_lshift (ptr, bs, bs2,&tab_bs[0]);
|
||||
}
|
||||
}
|
||||
|
||||
delta = small_diff (ptr, bb, bd,&tab_delta[0]);
|
||||
dsign = delta->_sign;
|
||||
delta->_sign = 0;
|
||||
i = small_cmp (delta, bs);
|
||||
|
||||
#endif
|
||||
if (i < 0)
|
||||
{
|
||||
/* Error is less than half an ulp -- check for
|
||||
* special case of mantissa a power of two.
|
||||
*/
|
||||
if (dsign || word1 (rv) || word0 (rv) & Bndry_mask)
|
||||
break;
|
||||
|
||||
#ifndef SMALL_SCANF
|
||||
delta = lshift (ptr, delta, Log2P);
|
||||
if (cmp (delta, bs) > 0)
|
||||
goto drop_down;
|
||||
#else
|
||||
if (delta == &tab_delta[0]){
|
||||
delta = small_lshift (ptr, delta, Log2P,&tab_deltalshift[0]);
|
||||
}
|
||||
else{
|
||||
delta = small_lshift (ptr, delta, Log2P,&tab_delta[0]);
|
||||
}
|
||||
if (small_cmp (delta, bs) > 0)
|
||||
goto drop_down;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
if (i == 0)
|
||||
{
|
||||
/* exactly half-way between */
|
||||
if (dsign)
|
||||
{
|
||||
if ((word0 (rv) & Bndry_mask1) == Bndry_mask1
|
||||
&& word1 (rv) == 0xffffffff)
|
||||
{
|
||||
/*boundary case -- increment exponent*/
|
||||
word0 (rv) = (word0 (rv) & Exp_mask)
|
||||
+ Exp_msk1
|
||||
#ifdef IBM
|
||||
| Exp_msk1 >> 4
|
||||
#endif
|
||||
;
|
||||
#ifndef _DOUBLE_IS_32BITS
|
||||
word1 (rv) = 0;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (!(word0 (rv) & Bndry_mask) && !word1 (rv))
|
||||
{
|
||||
drop_down:
|
||||
/* boundary case -- decrement exponent */
|
||||
#ifdef Sudden_Underflow
|
||||
L = word0 (rv) & Exp_mask;
|
||||
#ifdef IBM
|
||||
if (L < Exp_msk1)
|
||||
#else
|
||||
if (L <= Exp_msk1)
|
||||
#endif
|
||||
goto undfl;
|
||||
L -= Exp_msk1;
|
||||
#else
|
||||
L = (word0 (rv) & Exp_mask) - Exp_msk1;
|
||||
#endif
|
||||
word0 (rv) = L | Bndry_mask1;
|
||||
#ifndef _DOUBLE_IS_32BITS
|
||||
word1 (rv) = 0xffffffff;
|
||||
#endif
|
||||
#ifdef IBM
|
||||
goto cont;
|
||||
#else
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
#ifndef ROUND_BIASED
|
||||
if (!(word1 (rv) & LSB))
|
||||
break;
|
||||
#endif
|
||||
if (dsign)
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d += ulp (rv.d);
|
||||
#else
|
||||
rv.d += small_ulp (rv.d);
|
||||
#endif
|
||||
#ifndef ROUND_BIASED
|
||||
else
|
||||
{
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d -= ulp (rv.d);
|
||||
#else
|
||||
rv.d -= small_ulp (rv.d);
|
||||
#endif
|
||||
#ifndef Sudden_Underflow
|
||||
if (!rv.d)
|
||||
goto undfl;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef SMALL_SCANF
|
||||
if ((aadj = ratio (delta, bs)) <= 2.)
|
||||
{
|
||||
#else
|
||||
if ((aadj = small_ratio (delta, bs)) <= 2.)
|
||||
{
|
||||
#endif
|
||||
if (dsign)
|
||||
aadj = aadj1 = 1.;
|
||||
else if (word1 (rv) || word0 (rv) & Bndry_mask)
|
||||
{
|
||||
#ifndef Sudden_Underflow
|
||||
if (word1 (rv) == Tiny1 && !word0 (rv))
|
||||
goto undfl;
|
||||
#endif
|
||||
aadj = 1.;
|
||||
aadj1 = -1.;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* special case -- power of FLT_RADIX to be */
|
||||
/* rounded down... */
|
||||
|
||||
if (aadj < 2. / FLT_RADIX)
|
||||
aadj = 1. / FLT_RADIX;
|
||||
else
|
||||
aadj *= 0.5;
|
||||
aadj1 = -aadj;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
aadj *= 0.5;
|
||||
aadj1 = dsign ? aadj : -aadj;
|
||||
#ifdef Check_FLT_ROUNDS
|
||||
switch (FLT_ROUNDS)
|
||||
{
|
||||
case 2: /* towards +infinity */
|
||||
aadj1 -= 0.5;
|
||||
break;
|
||||
case 0: /* towards 0 */
|
||||
case 3: /* towards -infinity */
|
||||
aadj1 += 0.5;
|
||||
}
|
||||
#else
|
||||
if (FLT_ROUNDS == 0)
|
||||
aadj1 += 0.5;
|
||||
#endif
|
||||
}
|
||||
y = word0 (rv) & Exp_mask;
|
||||
|
||||
/* Check for overflow */
|
||||
|
||||
if (y == Exp_msk1 * (DBL_MAX_EXP + Bias - 1))
|
||||
{
|
||||
rv0.d = rv.d;
|
||||
word0 (rv) -= P * Exp_msk1;
|
||||
#ifndef SMALL_SCANF
|
||||
adj = aadj1 * ulp (rv.d);
|
||||
#else
|
||||
adj = aadj1 * small_ulp (rv.d);
|
||||
#endif
|
||||
rv.d += adj;
|
||||
if ((word0 (rv) & Exp_mask) >=
|
||||
Exp_msk1 * (DBL_MAX_EXP + Bias - P))
|
||||
{
|
||||
if (word0 (rv0) == Big0 && word1 (rv0) == Big1)
|
||||
goto ovfl;
|
||||
#ifdef _DOUBLE_IS_32BITS
|
||||
word0 (rv) = Big1;
|
||||
#else
|
||||
word0 (rv) = Big0;
|
||||
word1 (rv) = Big1;
|
||||
#endif
|
||||
goto cont;
|
||||
}
|
||||
else
|
||||
word0 (rv) += P * Exp_msk1;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef Sudden_Underflow
|
||||
if ((word0 (rv) & Exp_mask) <= P * Exp_msk1)
|
||||
{
|
||||
rv0.d = rv.d;
|
||||
word0 (rv) += P * Exp_msk1;
|
||||
#ifndef SMALL_SCANF
|
||||
adj = aadj1 * ulp (rv.d);
|
||||
#else
|
||||
adj = aadj1 * small_ulp (rv.d);
|
||||
#endif
|
||||
rv.d += adj;
|
||||
#ifdef IBM
|
||||
if ((word0 (rv) & Exp_mask) < P * Exp_msk1)
|
||||
#else
|
||||
if ((word0 (rv) & Exp_mask) <= P * Exp_msk1)
|
||||
#endif
|
||||
{
|
||||
if (word0 (rv0) == Tiny0
|
||||
&& word1 (rv0) == Tiny1)
|
||||
goto undfl;
|
||||
word0 (rv) = Tiny0;
|
||||
word1 (rv) = Tiny1;
|
||||
goto cont;
|
||||
}
|
||||
else
|
||||
word0 (rv) -= P * Exp_msk1;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef SMALL_SCANF
|
||||
adj = aadj1 * ulp (rv.d);
|
||||
#else
|
||||
adj = aadj1 * small_ulp (rv.d);
|
||||
#endif
|
||||
rv.d += adj;
|
||||
}
|
||||
#else
|
||||
/* Compute adj so that the IEEE rounding rules will
|
||||
* correctly round rv.d + adj in some half-way cases.
|
||||
* If rv.d * ulp(rv.d) is denormalized (i.e.,
|
||||
* y <= (P-1)*Exp_msk1), we must adjust aadj to avoid
|
||||
* trouble from bits lost to denormalization;
|
||||
* example: 1.2e-307 .
|
||||
*/
|
||||
if (y <= (P - 1) * Exp_msk1 && aadj >= 1.)
|
||||
{
|
||||
aadj1 = (double) (int) (aadj + 0.5);
|
||||
if (!dsign)
|
||||
aadj1 = -aadj1;
|
||||
}
|
||||
#ifndef SMALL_SCANF
|
||||
adj = aadj1 * ulp (rv.d);
|
||||
#else
|
||||
adj = aadj1 * small_ulp (rv.d);
|
||||
rv.d += adj;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
z = word0 (rv) & Exp_mask;
|
||||
if (y == z)
|
||||
{
|
||||
/* Can we stop now? */
|
||||
L = aadj;
|
||||
aadj -= L;
|
||||
/* The tolerances below are conservative. */
|
||||
if (dsign || word1 (rv) || word0 (rv) & Bndry_mask)
|
||||
{
|
||||
if (aadj < .4999999 || aadj > .5000001)
|
||||
break;
|
||||
}
|
||||
else if (aadj < .4999999 / FLT_RADIX)
|
||||
break;
|
||||
}
|
||||
cont:
|
||||
#ifndef SMALL_SCANF
|
||||
Bfree (ptr, bb);
|
||||
Bfree (ptr, bd);
|
||||
Bfree (ptr, bs);
|
||||
Bfree (ptr, delta);
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
}
|
||||
retfree:
|
||||
#ifndef SMALL_SCANF
|
||||
Bfree (ptr, bb);
|
||||
Bfree (ptr, bd);
|
||||
Bfree (ptr, bs);
|
||||
Bfree (ptr, bd0);
|
||||
Bfree (ptr, delta);
|
||||
#endif
|
||||
ret:
|
||||
if (se)
|
||||
*se = (char *) s;
|
||||
return sign ? -rv.d : rv.d;
|
||||
}
|
||||
|
||||
#ifndef NO_REENT
|
||||
|
||||
double
|
||||
_DEFUN (strtod, (s00, se),
|
||||
_CONST char *s00 _AND char **se)
|
||||
{
|
||||
return _strtod_r (_REENT, s00, se);
|
||||
}
|
||||
|
||||
float
|
||||
_DEFUN (strtof, (s00, se),
|
||||
_CONST char *s00 _AND
|
||||
char **se)
|
||||
{
|
||||
return (float)_strtod_r (_REENT, s00, se);
|
||||
}
|
||||
|
||||
#endif
|
1481
cpu/stm32w108/e_stdio/src/small_vfsscanf.c
Normal file
1481
cpu/stm32w108/e_stdio/src/small_vfsscanf.c
Normal file
File diff suppressed because it is too large
Load diff
59
cpu/stm32w108/e_stdio/src/small_wcrtomb.c
Normal file
59
cpu/stm32w108/e_stdio/src/small_wcrtomb.c
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include <reent.h>
|
||||
#include <wchar.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined( _SMALL_PRINTF ) || defined(SMALL_SCANF)
|
||||
#define _ASCII_CAR
|
||||
#endif
|
||||
|
||||
size_t
|
||||
_DEFUN (_wcrtomb_r, (ptr, s, wc, ps),
|
||||
struct _reent *ptr _AND
|
||||
char *s _AND
|
||||
wchar_t wc _AND
|
||||
mbstate_t *ps)
|
||||
{
|
||||
|
||||
#ifndef _ASCII_CAR
|
||||
int retval = 0;
|
||||
char buf[10];
|
||||
|
||||
|
||||
#ifdef MB_CAPABLE
|
||||
if (ps == NULL)
|
||||
{
|
||||
_REENT_CHECK_MISC(ptr);
|
||||
ps = &(_REENT_WCRTOMB_STATE(ptr));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (s == NULL)
|
||||
retval = _wctomb_r (ptr, buf, L'\0', ps);
|
||||
else
|
||||
retval = _wctomb_r (ptr, s, wc, ps);
|
||||
|
||||
if (retval == -1)
|
||||
{
|
||||
ps->__count = 0;
|
||||
ptr->_errno = EILSEQ;
|
||||
return (size_t)(-1);
|
||||
}
|
||||
else
|
||||
return (size_t)retval;
|
||||
#endif
|
||||
int retval = 1 ;
|
||||
return (size_t)retval;
|
||||
}
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
size_t
|
||||
_DEFUN (wcrtomb, (s, wc, ps),
|
||||
char *s _AND
|
||||
wchar_t wc _AND
|
||||
mbstate_t *ps)
|
||||
{
|
||||
return _wcrtomb_r (_REENT, s, wc, ps);
|
||||
}
|
||||
#endif /* !_REENT_ONLY */
|
97
cpu/stm32w108/e_stdio/src/small_wcsrtombs.c
Normal file
97
cpu/stm32w108/e_stdio/src/small_wcsrtombs.c
Normal file
|
@ -0,0 +1,97 @@
|
|||
#include <reent.h>
|
||||
#include <wchar.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined( _SMALL_PRINTF ) || defined(SMALL_SCANF)
|
||||
#define _ASCII_CAR
|
||||
#endif
|
||||
|
||||
size_t
|
||||
_DEFUN (_wcsrtombs_r, (r, dst, src, len, ps),
|
||||
struct _reent *r _AND
|
||||
char *dst _AND
|
||||
const wchar_t **src _AND
|
||||
size_t len _AND
|
||||
mbstate_t *ps)
|
||||
{
|
||||
|
||||
|
||||
char *ptr = dst;
|
||||
char buff[10];
|
||||
wchar_t *pwcs;
|
||||
size_t n;
|
||||
int i;
|
||||
|
||||
#ifdef MB_CAPABLE
|
||||
if (ps == NULL)
|
||||
{
|
||||
_REENT_CHECK_MISC(r);
|
||||
ps = &(_REENT_WCSRTOMBS_STATE(r));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If no dst pointer, treat len as maximum possible value. */
|
||||
if (dst == NULL)
|
||||
len = (size_t)-1;
|
||||
|
||||
n = 0;
|
||||
pwcs = (wchar_t *)(*src);
|
||||
|
||||
while (n < len)
|
||||
{
|
||||
int count = ps->__count;
|
||||
wint_t wch = ps->__value.__wch;
|
||||
#ifndef _ASCII_CAR
|
||||
int bytes = _wcrtomb_r (r, buff, *pwcs, ps);
|
||||
if (bytes == -1)
|
||||
{
|
||||
r->_errno = EILSEQ;
|
||||
ps->__count = 0;
|
||||
return (size_t)-1;
|
||||
}
|
||||
#else
|
||||
int bytes = 1 ;
|
||||
#endif
|
||||
|
||||
if (n <= len - bytes && bytes < len)
|
||||
{
|
||||
n += bytes;
|
||||
if (dst)
|
||||
{
|
||||
for (i = 0; i < bytes; ++i)
|
||||
*ptr++ = buff[i];
|
||||
++(*src);
|
||||
}
|
||||
if (*pwcs++ == 0x00)
|
||||
{
|
||||
if (dst)
|
||||
*src = NULL;
|
||||
ps->__count = 0;
|
||||
return n - 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* not enough room, we must back up state to before _wctomb_r call */
|
||||
ps->__count = count;
|
||||
ps->__value.__wch = wch;
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
size_t
|
||||
_DEFUN (wcsrtombs, (dst, src, len, ps),
|
||||
char *dst _AND
|
||||
const wchar_t **src _AND
|
||||
size_t len _AND
|
||||
mbstate_t *ps)
|
||||
{
|
||||
return _wcsrtombs_r (_REENT, dst, src, len, ps);
|
||||
}
|
||||
#endif /* !_REENT_ONLY */
|
188
cpu/stm32w108/e_stdio/src/small_wctomb_r.c
Normal file
188
cpu/stm32w108/e_stdio/src/small_wctomb_r.c
Normal file
|
@ -0,0 +1,188 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <locale.h>
|
||||
#include "mbctype.h"
|
||||
|
||||
/* The following function concerns caracter coded in more than 0ne byte. For our small_printf we considered only
|
||||
caracters coded in ASCII and therefore all our caracters are coded in 8 bits (One byte)
|
||||
If you need the following treatment because caracter that you use are coded in more than one byte
|
||||
comment the three following lines */
|
||||
|
||||
#if defined( _SMALL_PRINTF ) || defined(SMALL_SCANF)
|
||||
#define _ASCII_CAR
|
||||
#endif
|
||||
|
||||
|
||||
/* for some conversions, we use the __count field as a place to store a state value */
|
||||
#define __state __count
|
||||
|
||||
#ifndef _ASCII_CAR
|
||||
extern char __lc_ctype[12];
|
||||
#endif
|
||||
int
|
||||
_DEFUN (_wctomb_r, (r, s, wchar, state),
|
||||
struct _reent *r _AND
|
||||
char *s _AND
|
||||
wchar_t wchar _AND
|
||||
mbstate_t *state)
|
||||
{
|
||||
|
||||
#ifndef _ASCII_CAR
|
||||
|
||||
if (strlen (__lc_ctype) <= 1)
|
||||
{ /* fall-through */ }
|
||||
else if (!strcmp (__lc_ctype, "C-UTF-8"))
|
||||
{
|
||||
if (s == NULL)
|
||||
return 0; /* UTF-8 encoding is not state-dependent */
|
||||
|
||||
if (wchar <= 0x7f)
|
||||
{
|
||||
*s = wchar;
|
||||
return 1;
|
||||
}
|
||||
else if (wchar >= 0x80 && wchar <= 0x7ff)
|
||||
{
|
||||
*s++ = 0xc0 | ((wchar & 0x7c0) >> 6);
|
||||
*s = 0x80 | (wchar & 0x3f);
|
||||
return 2;
|
||||
}
|
||||
else if (wchar >= 0x800 && wchar <= 0xffff)
|
||||
{
|
||||
/* UTF-16 surrogates -- must not occur in normal UCS-4 data */
|
||||
if (wchar >= 0xd800 && wchar <= 0xdfff)
|
||||
return -1;
|
||||
|
||||
*s++ = 0xe0 | ((wchar & 0xf000) >> 12);
|
||||
*s++ = 0x80 | ((wchar & 0xfc0) >> 6);
|
||||
*s = 0x80 | (wchar & 0x3f);
|
||||
return 3;
|
||||
}
|
||||
else if (wchar >= 0x10000 && wchar <= 0x1fffff)
|
||||
{
|
||||
*s++ = 0xf0 | ((wchar & 0x1c0000) >> 18);
|
||||
*s++ = 0x80 | ((wchar & 0x3f000) >> 12);
|
||||
*s++ = 0x80 | ((wchar & 0xfc0) >> 6);
|
||||
*s = 0x80 | (wchar & 0x3f);
|
||||
return 4;
|
||||
}
|
||||
else if (wchar >= 0x200000 && wchar <= 0x3ffffff)
|
||||
{
|
||||
*s++ = 0xf8 | ((wchar & 0x3000000) >> 24);
|
||||
*s++ = 0x80 | ((wchar & 0xfc0000) >> 18);
|
||||
*s++ = 0x80 | ((wchar & 0x3f000) >> 12);
|
||||
*s++ = 0x80 | ((wchar & 0xfc0) >> 6);
|
||||
*s = 0x80 | (wchar & 0x3f);
|
||||
return 5;
|
||||
}
|
||||
else if (wchar >= 0x4000000 && wchar <= 0x7fffffff)
|
||||
{
|
||||
*s++ = 0xfc | ((wchar & 0x40000000) >> 30);
|
||||
*s++ = 0x80 | ((wchar & 0x3f000000) >> 24);
|
||||
*s++ = 0x80 | ((wchar & 0xfc0000) >> 18);
|
||||
*s++ = 0x80 | ((wchar & 0x3f000) >> 12);
|
||||
*s++ = 0x80 | ((wchar & 0xfc0) >> 6);
|
||||
*s = 0x80 | (wchar & 0x3f);
|
||||
return 6;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else if (!strcmp (__lc_ctype, "C-SJIS"))
|
||||
{
|
||||
unsigned char char2 = (unsigned char)wchar;
|
||||
unsigned char char1 = (unsigned char)(wchar >> 8);
|
||||
|
||||
if (s == NULL)
|
||||
return 0; /* not state-dependent */
|
||||
|
||||
if (char1 != 0x00)
|
||||
{
|
||||
/* first byte is non-zero..validate multi-byte char */
|
||||
if (_issjis1(char1) && _issjis2(char2))
|
||||
{
|
||||
*s++ = (char)char1;
|
||||
*s = (char)char2;
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (!strcmp (__lc_ctype, "C-EUCJP"))
|
||||
{
|
||||
unsigned char char2 = (unsigned char)wchar;
|
||||
unsigned char char1 = (unsigned char)(wchar >> 8);
|
||||
|
||||
if (s == NULL)
|
||||
return 0; /* not state-dependent */
|
||||
|
||||
if (char1 != 0x00)
|
||||
{
|
||||
/* first byte is non-zero..validate multi-byte char */
|
||||
if (_iseucjp (char1) && _iseucjp (char2))
|
||||
{
|
||||
*s++ = (char)char1;
|
||||
*s = (char)char2;
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (!strcmp (__lc_ctype, "C-JIS"))
|
||||
{
|
||||
int cnt = 0;
|
||||
unsigned char char2 = (unsigned char)wchar;
|
||||
unsigned char char1 = (unsigned char)(wchar >> 8);
|
||||
|
||||
if (s == NULL)
|
||||
return 1; /* state-dependent */
|
||||
|
||||
if (char1 != 0x00)
|
||||
{
|
||||
/* first byte is non-zero..validate multi-byte char */
|
||||
if (_isjis (char1) && _isjis (char2))
|
||||
{
|
||||
if (state->__state == 0)
|
||||
{
|
||||
/* must switch from ASCII to JIS state */
|
||||
state->__state = 1;
|
||||
*s++ = ESC_CHAR;
|
||||
*s++ = '$';
|
||||
*s++ = 'B';
|
||||
cnt = 3;
|
||||
}
|
||||
*s++ = (char)char1;
|
||||
*s = (char)char2;
|
||||
return cnt + 2;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (state->__state != 0)
|
||||
{
|
||||
/* must switch from JIS to ASCII state */
|
||||
state->__state = 0;
|
||||
*s++ = ESC_CHAR;
|
||||
*s++ = '(';
|
||||
*s++ = 'B';
|
||||
cnt = 3;
|
||||
}
|
||||
*s = (char)char2;
|
||||
return cnt + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (s == NULL)
|
||||
return 0;
|
||||
#endif
|
||||
/* otherwise we are dealing with a single byte character */
|
||||
*s = (char) wchar;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
453
cpu/stm32w108/e_stdio/src/sscanf.c
Normal file
453
cpu/stm32w108/e_stdio/src/sscanf.c
Normal file
|
@ -0,0 +1,453 @@
|
|||
/*
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
FUNCTION
|
||||
<<scanf>>, <<fscanf>>, <<sscanf>>---scan and format input
|
||||
|
||||
INDEX
|
||||
scanf
|
||||
INDEX
|
||||
fscanf
|
||||
INDEX
|
||||
sscanf
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdio.h>
|
||||
|
||||
int scanf(const char *<[format]> [, <[arg]>, ...]);
|
||||
int fscanf(FILE *<[fd]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
int sscanf(const char *<[str]>, const char *<[format]>
|
||||
[, <[arg]>, ...]);
|
||||
|
||||
int _scanf_r(struct _reent *<[ptr]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
int _fscanf_r(struct _reent *<[ptr]>, FILE *<[fd]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
int _sscanf_r(struct _reent *<[ptr]>, const char *<[str]>, const char *<[format]>
|
||||
[, <[arg]>, ...]);
|
||||
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdio.h>
|
||||
|
||||
int scanf(<[format]> [, <[arg]>, ...])
|
||||
char *<[format]>;
|
||||
|
||||
int fscanf(<[fd]>, <[format]> [, <[arg]>, ...]);
|
||||
FILE *<[fd]>;
|
||||
char *<[format]>;
|
||||
|
||||
int sscanf(<[str]>, <[format]> [, <[arg]>, ...]);
|
||||
char *<[str]>;
|
||||
char *<[format]>;
|
||||
|
||||
int _scanf_r(<[ptr]>, <[format]> [, <[arg]>, ...])
|
||||
struct _reent *<[ptr]>;
|
||||
char *<[format]>;
|
||||
|
||||
int _fscanf_r(<[ptr]>, <[fd]>, <[format]> [, <[arg]>, ...]);
|
||||
struct _reent *<[ptr]>;
|
||||
FILE *<[fd]>;
|
||||
char *<[format]>;
|
||||
|
||||
int _sscanf_r(<[ptr]>, <[str]>, <[format]> [, <[arg]>, ...]);
|
||||
struct _reent *<[ptr]>;
|
||||
char *<[str]>;
|
||||
char *<[format]>;
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
<<scanf>> scans a series of input fields from standard input,
|
||||
one character at a time. Each field is interpreted according to
|
||||
a format specifier passed to <<scanf>> in the format string at
|
||||
<<*<[format]>>>. <<scanf>> stores the interpreted input from
|
||||
each field at the address passed to it as the corresponding argument
|
||||
following <[format]>. You must supply the same number of
|
||||
format specifiers and address arguments as there are input fields.
|
||||
|
||||
There must be sufficient address arguments for the given format
|
||||
specifiers; if not the results are unpredictable and likely
|
||||
disasterous. Excess address arguments are merely ignored.
|
||||
|
||||
<<scanf>> often produces unexpected results if the input diverges from
|
||||
an expected pattern. Since the combination of <<gets>> or <<fgets>>
|
||||
followed by <<sscanf>> is safe and easy, that is the preferred way
|
||||
to be certain that a program is synchronized with input at the end
|
||||
of a line.
|
||||
|
||||
<<fscanf>> and <<sscanf>> are identical to <<scanf>>, other than the
|
||||
source of input: <<fscanf>> reads from a file, and <<sscanf>>
|
||||
from a string.
|
||||
|
||||
The routines <<_scanf_r>>, <<_fscanf_r>>, and <<_sscanf_r>> are reentrant
|
||||
versions of <<scanf>>, <<fscanf>>, and <<sscanf>> that take an additional
|
||||
first argument pointing to a reentrancy structure.
|
||||
|
||||
The string at <<*<[format]>>> is a character sequence composed
|
||||
of zero or more directives. Directives are composed of
|
||||
one or more whitespace characters, non-whitespace characters,
|
||||
and format specifications.
|
||||
|
||||
Whitespace characters are blank (<< >>), tab (<<\t>>), or
|
||||
newline (<<\n>>).
|
||||
When <<scanf>> encounters a whitespace character in the format string
|
||||
it will read (but not store) all consecutive whitespace characters
|
||||
up to the next non-whitespace character in the input.
|
||||
|
||||
Non-whitespace characters are all other ASCII characters except the
|
||||
percent sign (<<%>>). When <<scanf>> encounters a non-whitespace
|
||||
character in the format string it will read, but not store
|
||||
a matching non-whitespace character.
|
||||
|
||||
Format specifications tell <<scanf>> to read and convert characters
|
||||
from the input field into specific types of values, and store then
|
||||
in the locations specified by the address arguments.
|
||||
|
||||
Trailing whitespace is left unread unless explicitly
|
||||
matched in the format string.
|
||||
|
||||
The format specifiers must begin with a percent sign (<<%>>)
|
||||
and have the following form:
|
||||
|
||||
. %[*][<[width]>][<[size]>]<[type]>
|
||||
|
||||
Each format specification begins with the percent character (<<%>>).
|
||||
The other fields are:
|
||||
o+
|
||||
o *
|
||||
an optional marker; if present, it suppresses interpretation and
|
||||
assignment of this input field.
|
||||
|
||||
o <[width]>
|
||||
an optional maximum field width: a decimal integer,
|
||||
which controls the maximum number of characters that
|
||||
will be read before converting the current input field. If the
|
||||
input field has fewer than <[width]> characters, <<scanf>>
|
||||
reads all the characters in the field, and then
|
||||
proceeds with the next field and its format specification.
|
||||
|
||||
If a whitespace or a non-convertable character occurs
|
||||
before <[width]> character are read, the characters up
|
||||
to that character are read, converted, and stored.
|
||||
Then <<scanf>> proceeds to the next format specification.
|
||||
|
||||
o size
|
||||
<<h>>, <<l>>, and <<L>> are optional size characters which
|
||||
override the default way that <<scanf>> interprets the
|
||||
data type of the corresponding argument.
|
||||
|
||||
|
||||
.Modifier Type(s)
|
||||
. hh d, i, o, u, x, n convert input to char,
|
||||
. store in char object
|
||||
.
|
||||
. h d, i, o, u, x, n convert input to short,
|
||||
. store in short object
|
||||
.
|
||||
. h D, I, O, U, X no effect
|
||||
. e, f, c, s, p
|
||||
.
|
||||
. l d, i, o, u, x, n convert input to long,
|
||||
. store in long object
|
||||
.
|
||||
. l e, f, g convert input to double
|
||||
. store in a double object
|
||||
.
|
||||
. l D, I, O, U, X no effect
|
||||
. c, s, p
|
||||
.
|
||||
. ll d, i, o, u, x, n convert to long long,
|
||||
. store in long long
|
||||
.
|
||||
. L d, i, o, u, x, n convert to long long,
|
||||
. store in long long
|
||||
.
|
||||
. L e, f, g, E, G convert to long double,
|
||||
. store in long double
|
||||
.
|
||||
. L all others no effect
|
||||
|
||||
|
||||
o <[type]>
|
||||
|
||||
A character to specify what kind of conversion
|
||||
<<scanf>> performs. Here is a table of the conversion
|
||||
characters:
|
||||
|
||||
o+
|
||||
o %
|
||||
No conversion is done; the percent character (<<%>>) is stored.
|
||||
|
||||
o c
|
||||
Scans one character. Corresponding <[arg]>: <<(char *arg)>>.
|
||||
|
||||
o s
|
||||
Reads a character string into the array supplied.
|
||||
Corresponding <[arg]>: <<(char arg[])>>.
|
||||
|
||||
o [<[pattern]>]
|
||||
Reads a non-empty character string into memory
|
||||
starting at <[arg]>. This area must be large
|
||||
enough to accept the sequence and a
|
||||
terminating null character which will be added
|
||||
automatically. (<[pattern]> is discussed in the paragraph following
|
||||
this table). Corresponding <[arg]>: <<(char *arg)>>.
|
||||
|
||||
o d
|
||||
Reads a decimal integer into the corresponding <[arg]>: <<(int *arg)>>.
|
||||
|
||||
o D
|
||||
Reads a decimal integer into the corresponding
|
||||
<[arg]>: <<(long *arg)>>.
|
||||
|
||||
o o
|
||||
Reads an octal integer into the corresponding <[arg]>: <<(int *arg)>>.
|
||||
|
||||
o O
|
||||
Reads an octal integer into the corresponding <[arg]>: <<(long *arg)>>.
|
||||
|
||||
o u
|
||||
Reads an unsigned decimal integer into the corresponding
|
||||
<[arg]>: <<(unsigned int *arg)>>.
|
||||
|
||||
|
||||
o U
|
||||
Reads an unsigned decimal integer into the corresponding <[arg]>:
|
||||
<<(unsigned long *arg)>>.
|
||||
|
||||
o x,X
|
||||
Read a hexadecimal integer into the corresponding <[arg]>:
|
||||
<<(int *arg)>>.
|
||||
|
||||
o e, f, g
|
||||
Read a floating-point number into the corresponding <[arg]>:
|
||||
<<(float *arg)>>.
|
||||
|
||||
o E, F, G
|
||||
Read a floating-point number into the corresponding <[arg]>:
|
||||
<<(double *arg)>>.
|
||||
|
||||
o i
|
||||
Reads a decimal, octal or hexadecimal integer into the
|
||||
corresponding <[arg]>: <<(int *arg)>>.
|
||||
|
||||
o I
|
||||
Reads a decimal, octal or hexadecimal integer into the
|
||||
corresponding <[arg]>: <<(long *arg)>>.
|
||||
|
||||
o n
|
||||
Stores the number of characters read in the corresponding
|
||||
<[arg]>: <<(int *arg)>>.
|
||||
|
||||
o p
|
||||
Stores a scanned pointer. ANSI C leaves the details
|
||||
to each implementation; this implementation treats
|
||||
<<%p>> exactly the same as <<%U>>. Corresponding
|
||||
<[arg]>: <<(void **arg)>>.
|
||||
o-
|
||||
|
||||
A <[pattern]> of characters surrounded by square brackets can be used
|
||||
instead of the <<s>> type character. <[pattern]> is a set of
|
||||
characters which define a search set of possible characters making up
|
||||
the <<scanf>> input field. If the first character in the brackets is a
|
||||
caret (<<^>>), the search set is inverted to include all ASCII characters
|
||||
except those between the brackets. There is also a range facility
|
||||
which you can use as a shortcut. <<%[0-9] >> matches all decimal digits.
|
||||
The hyphen must not be the first or last character in the set.
|
||||
The character prior to the hyphen must be lexically less than the
|
||||
character after it.
|
||||
|
||||
Here are some <[pattern]> examples:
|
||||
o+
|
||||
o %[abcd]
|
||||
matches strings containing only <<a>>, <<b>>, <<c>>, and <<d>>.
|
||||
|
||||
o %[^abcd]
|
||||
matches strings containing any characters except <<a>>, <<b>>,
|
||||
<<c>>, or <<d>>
|
||||
|
||||
o %[A-DW-Z]
|
||||
matches strings containing <<A>>, <<B>>, <<C>>, <<D>>, <<W>>,
|
||||
<<X>>, <<Y>>, <<Z>>
|
||||
|
||||
o %[z-a]
|
||||
matches the characters <<z>>, <<->>, and <<a>>
|
||||
o-
|
||||
|
||||
Floating point numbers (for field types <<e>>, <<f>>, <<g>>, <<E>>,
|
||||
<<F>>, <<G>>) must correspond to the following general form:
|
||||
|
||||
. [+/-] ddddd[.]ddd [E|e[+|-]ddd]
|
||||
|
||||
where objects inclosed in square brackets are optional, and <<ddd>>
|
||||
represents decimal, octal, or hexadecimal digits.
|
||||
o-
|
||||
|
||||
RETURNS
|
||||
<<scanf>> returns the number of input fields successfully
|
||||
scanned, converted and stored; the return value does
|
||||
not include scanned fields which were not stored.
|
||||
|
||||
If <<scanf>> attempts to read at end-of-file, the return
|
||||
value is <<EOF>>.
|
||||
|
||||
If no fields were stored, the return value is <<0>>.
|
||||
|
||||
<<scanf>> might stop scanning a particular field before
|
||||
reaching the normal field end character, or may
|
||||
terminate entirely.
|
||||
|
||||
<<scanf>> stops scanning and storing the current field
|
||||
and moves to the next input field (if any)
|
||||
in any of the following situations:
|
||||
|
||||
O+
|
||||
o The assignment suppressing character (<<*>>) appears
|
||||
after the <<%>> in the format specification; the current
|
||||
input field is scanned but not stored.
|
||||
|
||||
o <[width]> characters have been read (<[width]> is a
|
||||
width specification, a positive decimal integer).
|
||||
|
||||
o The next character read cannot be converted
|
||||
under the the current format (for example,
|
||||
if a <<Z>> is read when the format is decimal).
|
||||
|
||||
o The next character in the input field does not appear
|
||||
in the search set (or does appear in the inverted search set).
|
||||
O-
|
||||
|
||||
When <<scanf>> stops scanning the current input field for one of
|
||||
these reasons, the next character is considered unread and
|
||||
used as the first character of the following input field, or the
|
||||
first character in a subsequent read operation on the input.
|
||||
|
||||
<<scanf>> will terminate under the following circumstances:
|
||||
|
||||
O+
|
||||
o The next character in the input field conflicts
|
||||
with a corresponding non-whitespace character in the
|
||||
format string.
|
||||
|
||||
o The next character in the input field is <<EOF>>.
|
||||
|
||||
o The format string has been exhausted.
|
||||
O-
|
||||
|
||||
When the format string contains a character sequence that is
|
||||
not part of a format specification, the same character
|
||||
sequence must appear in the input; <<scanf>> will
|
||||
scan but not store the matched characters. If a
|
||||
conflict occurs, the first conflicting character remains in the input
|
||||
as if it had never been read.
|
||||
|
||||
PORTABILITY
|
||||
<<scanf>> is ANSI C.
|
||||
|
||||
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
||||
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <reent.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifdef _HAVE_STDC
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
#include "local.h"
|
||||
|
||||
/* | ARGSUSED */
|
||||
/*SUPPRESS 590*/
|
||||
static
|
||||
_READ_WRITE_RETURN_TYPE
|
||||
eofread (cookie, buf, len)
|
||||
_PTR cookie;
|
||||
char *buf;
|
||||
int len;
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
#ifdef _HAVE_STDC
|
||||
int
|
||||
_DEFUN (sscanf, (str, fmt), _CONST char *str _AND _CONST char *fmt _DOTS)
|
||||
#else
|
||||
int
|
||||
sscanf (str, fmt, va_alist)
|
||||
_CONST char *str;
|
||||
_CONST char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
FILE f;
|
||||
|
||||
f._flags = __SRD;
|
||||
f._bf._base = f._p = (unsigned char *) str;
|
||||
f._bf._size = f._r = strlen (str);
|
||||
f._read = eofread;
|
||||
f._ub._base = NULL;
|
||||
f._lb._base = NULL;
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = __svfscanf_r (_REENT, &f, fmt, ap);
|
||||
va_end (ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* !_REENT_ONLY */
|
||||
|
||||
#ifdef _HAVE_STDC
|
||||
int
|
||||
_DEFUN (_sscanf_r, (ptr, str, fmt), struct _reent *ptr _AND _CONST char *str _AND _CONST char *fmt _DOTS)
|
||||
#else
|
||||
int
|
||||
_sscanf_r (ptr, str, fmt, va_alist)
|
||||
struct _reent *ptr;
|
||||
_CONST char *str;
|
||||
_CONST char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
FILE f;
|
||||
|
||||
f._flags = __SRD;
|
||||
f._bf._base = f._p = (unsigned char *) str;
|
||||
f._bf._size = f._r = strlen (str);
|
||||
f._read = eofread;
|
||||
f._ub._base = NULL;
|
||||
f._lb._base = NULL;
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = __svfscanf_r (ptr, &f, fmt, ap);
|
||||
va_end (ap);
|
||||
return ret;
|
||||
}
|
60
cpu/stm32w108/e_stdio/src/swi.h
Normal file
60
cpu/stm32w108/e_stdio/src/swi.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/* SWI numbers for RDP (Demon) monitor. */
|
||||
#define SWI_WriteC 0x0
|
||||
#define SWI_Write0 0x2
|
||||
#define SWI_ReadC 0x4
|
||||
#define SWI_CLI 0x5
|
||||
#define SWI_GetEnv 0x10
|
||||
#define SWI_Exit 0x11
|
||||
#define SWI_EnterOS 0x16
|
||||
|
||||
#define SWI_GetErrno 0x60
|
||||
#define SWI_Clock 0x61
|
||||
#define SWI_Time 0x63
|
||||
#define SWI_Remove 0x64
|
||||
#define SWI_Rename 0x65
|
||||
#define SWI_Open 0x66
|
||||
|
||||
#define SWI_Close 0x68
|
||||
#define SWI_Write 0x69
|
||||
#define SWI_Read 0x6a
|
||||
#define SWI_Seek 0x6b
|
||||
#define SWI_Flen 0x6c
|
||||
|
||||
#define SWI_IsTTY 0x6e
|
||||
#define SWI_TmpNam 0x6f
|
||||
#define SWI_InstallHandler 0x70
|
||||
#define SWI_GenerateError 0x71
|
||||
|
||||
|
||||
/* Now the SWI numbers and reason codes for RDI (Angel) monitors. */
|
||||
#define AngelSWI_ARM 0x123456
|
||||
#ifdef __thumb__
|
||||
#define AngelSWI 0xAB
|
||||
#else
|
||||
#define AngelSWI AngelSWI_ARM
|
||||
#endif
|
||||
|
||||
/* The reason codes: */
|
||||
#define AngelSWI_Reason_Open 0x01
|
||||
#define AngelSWI_Reason_Close 0x02
|
||||
#define AngelSWI_Reason_WriteC 0x03
|
||||
#define AngelSWI_Reason_Write0 0x04
|
||||
#define AngelSWI_Reason_Write 0x05
|
||||
#define AngelSWI_Reason_Read 0x06
|
||||
#define AngelSWI_Reason_ReadC 0x07
|
||||
#define AngelSWI_Reason_IsTTY 0x09
|
||||
#define AngelSWI_Reason_Seek 0x0A
|
||||
#define AngelSWI_Reason_FLen 0x0C
|
||||
#define AngelSWI_Reason_TmpNam 0x0D
|
||||
#define AngelSWI_Reason_Remove 0x0E
|
||||
#define AngelSWI_Reason_Rename 0x0F
|
||||
#define AngelSWI_Reason_Clock 0x10
|
||||
#define AngelSWI_Reason_Time 0x11
|
||||
#define AngelSWI_Reason_System 0x12
|
||||
#define AngelSWI_Reason_Errno 0x13
|
||||
#define AngelSWI_Reason_GetCmdLine 0x15
|
||||
#define AngelSWI_Reason_HeapInfo 0x16
|
||||
#define AngelSWI_Reason_EnterSVC 0x17
|
||||
#define AngelSWI_Reason_ReportException 0x18
|
||||
#define ADP_Stopped_ApplicationExit ((2 << 16) + 38)
|
||||
#define ADP_Stopped_RunTimeError ((2 << 16) + 35)
|
403
cpu/stm32w108/e_stdio/src/syscalls.c
Normal file
403
cpu/stm32w108/e_stdio/src/syscalls.c
Normal file
|
@ -0,0 +1,403 @@
|
|||
/* Support files for GNU libc. Files in the system namespace go here.
|
||||
Files in the C namespace (ie those that do not start with an
|
||||
underscore) go in .c. */
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
/*You can comment this three lines if you want to use _gettimeofday and _times*/
|
||||
|
||||
|
||||
#if defined(_SMALL_PRINTF) || defined(SMALL_SCANF)
|
||||
#define NO_TIME
|
||||
#endif
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef NO_TIME
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <reent.h>
|
||||
#include <unistd.h>
|
||||
#include "swi.h"
|
||||
|
||||
/* Forward prototypes. */
|
||||
|
||||
int _system _PARAMS ((const char *));
|
||||
|
||||
|
||||
|
||||
int _rename _PARAMS ((const char *, const char *));
|
||||
int isatty _PARAMS ((int));
|
||||
|
||||
#ifndef NO_TIME
|
||||
clock_t _times _PARAMS ((struct tms *));
|
||||
int _gettimeofday _PARAMS ((struct timeval *, struct timezone *));
|
||||
#endif
|
||||
|
||||
|
||||
void _raise _PARAMS ((void));
|
||||
|
||||
int _unlink _PARAMS ((void));
|
||||
int _link _PARAMS ((void));
|
||||
|
||||
int _stat _PARAMS ((const char *, struct stat *));
|
||||
|
||||
int _fstat _PARAMS ((int, struct stat *));
|
||||
|
||||
//caddr_t _sbrk _PARAMS ((int));
|
||||
int _getpid _PARAMS ((int));
|
||||
|
||||
int _kill _PARAMS ((int, int));
|
||||
void _exit _PARAMS ((int));
|
||||
int _close _PARAMS ((int));
|
||||
|
||||
int _swiclose _PARAMS ((int));
|
||||
int _open _PARAMS ((const char *, int, ...));
|
||||
int _swiopen _PARAMS ((const char *, int));
|
||||
int _write _PARAMS ((int, char *, int));
|
||||
int _swiwrite _PARAMS ((int, char *, int));
|
||||
int _lseek _PARAMS ((int, int, int));
|
||||
int _swilseek _PARAMS ((int, int, int));
|
||||
int _read _PARAMS ((int, char *, int));
|
||||
int _swiread _PARAMS ((int, char *, int));
|
||||
void initialise_monitor_handles _PARAMS ((void));
|
||||
|
||||
static int wrap _PARAMS ((int));
|
||||
static int error _PARAMS ((int));
|
||||
static int get_errno _PARAMS ((void));
|
||||
static int remap_handle _PARAMS ((int));
|
||||
static int findslot _PARAMS ((int));
|
||||
|
||||
/* Register name faking - works in collusion with the linker. */
|
||||
register char * stack_ptr asm ("sp");
|
||||
|
||||
|
||||
/* following is copied from libc/stdio/local.h to check std streams */
|
||||
extern void _EXFUN(__sinit,(struct _reent *));
|
||||
|
||||
#ifndef _SMALL_PRINTF
|
||||
#define CHECK_INIT(fp) \
|
||||
do \
|
||||
{ \
|
||||
if ((fp)->_data == 0) \
|
||||
(fp)->_data = _REENT; \
|
||||
if (!(fp)->_data->__sdidinit) \
|
||||
__sinit ((fp)->_data); \
|
||||
} \
|
||||
while (0)
|
||||
#endif
|
||||
/* Adjust our internal handles to stay away from std* handles. */
|
||||
#define FILE_HANDLE_OFFSET (0x20)
|
||||
|
||||
static int std_files_checked;
|
||||
static int monitor_stdin;
|
||||
static int monitor_stdout;
|
||||
static int monitor_stderr;
|
||||
|
||||
/* Struct used to keep track of the file position, just so we
|
||||
can implement fseek(fh,x,SEEK_CUR). */
|
||||
typedef struct
|
||||
{
|
||||
int handle;
|
||||
int pos;
|
||||
}
|
||||
poslog;
|
||||
|
||||
#define MAX_OPEN_FILES 20
|
||||
static poslog openfiles [MAX_OPEN_FILES];
|
||||
/*
|
||||
static int findslot (int fh)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < MAX_OPEN_FILES; i ++)
|
||||
if (openfiles[i].handle == fh)
|
||||
break;
|
||||
return i;
|
||||
}
|
||||
*/
|
||||
|
||||
/* Function to convert std(in|out|err) handles to internal versions. */
|
||||
/*
|
||||
static int remap_handle (int fh)
|
||||
{
|
||||
if (!std_files_checked)
|
||||
{
|
||||
CHECK_INIT(stdin);
|
||||
CHECK_INIT(stdout);
|
||||
CHECK_INIT(stderr);
|
||||
std_files_checked = 1;
|
||||
}
|
||||
if (fh == STDIN_FILENO)
|
||||
return monitor_stdin;
|
||||
if (fh == STDOUT_FILENO)
|
||||
return monitor_stdout;
|
||||
if (fh == STDERR_FILENO)
|
||||
return monitor_stderr;
|
||||
|
||||
return fh - FILE_HANDLE_OFFSET;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
void
|
||||
initialise_monitor_handles (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
int fh;
|
||||
const char * name;
|
||||
|
||||
name = ":tt";
|
||||
asm ("mov r0,%2; mov r1, #0; swi %a1; mov %0, r0"
|
||||
: "=r"(fh)
|
||||
: "i" (SWI_Open),"r"(name)
|
||||
: "r0","r1");
|
||||
monitor_stdin = fh;
|
||||
|
||||
name = ":tt";
|
||||
asm ("mov r0,%2; mov r1, #4; swi %a1; mov %0, r0"
|
||||
: "=r"(fh)
|
||||
: "i" (SWI_Open),"r"(name)
|
||||
: "r0","r1");
|
||||
monitor_stdout = monitor_stderr = fh;
|
||||
|
||||
for (i = 0; i < MAX_OPEN_FILES; i ++)
|
||||
openfiles[i].handle = -1;
|
||||
|
||||
openfiles[0].handle = monitor_stdin;
|
||||
openfiles[0].pos = 0;
|
||||
openfiles[1].handle = monitor_stdout;
|
||||
openfiles[1].pos = 0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
static int get_errno (void)
|
||||
{
|
||||
asm ("swi %a0" :: "i" (SWI_GetErrno));
|
||||
}
|
||||
|
||||
static int error (int result)
|
||||
{
|
||||
errno = get_errno ();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int wrap (int result)
|
||||
{
|
||||
if (result == -1)
|
||||
return error (-1);
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef NO_FILE
|
||||
int _read (int file,
|
||||
char * ptr,
|
||||
int len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _lseek (int file,
|
||||
int ptr,
|
||||
int dir)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern void __io_putchar( char c );
|
||||
|
||||
int _write (int file,
|
||||
char * ptr,
|
||||
int len)
|
||||
{
|
||||
int todo;
|
||||
|
||||
for (todo = 0; todo < len; todo++)
|
||||
{
|
||||
__io_putchar( *ptr++ );
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int _open (const char * path,
|
||||
int flags,
|
||||
...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _close (int file)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
void _exit (int n)
|
||||
{
|
||||
/* FIXME: return code is thrown away. */
|
||||
while(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _kill (int n, int m)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
#if 0 //VC090825: moved to independent lib std_sbrk.lib
|
||||
caddr_t _sbrk (int incr)
|
||||
{
|
||||
extern char end; /* Defined by the linker */
|
||||
static char *heap_end;
|
||||
char *prev_heap_end;
|
||||
|
||||
if (heap_end == 0) {
|
||||
heap_end = &end;
|
||||
}
|
||||
prev_heap_end = heap_end;
|
||||
if (heap_end + incr > stack_ptr)
|
||||
{
|
||||
_write (1, "Heap and stack collision\n", 25);
|
||||
abort ();
|
||||
}
|
||||
|
||||
heap_end += incr;
|
||||
return (caddr_t) prev_heap_end;
|
||||
}
|
||||
#endif //if 0 //VC090825: moved to independent lib std_sbrk.lib
|
||||
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifndef NO_FILE
|
||||
int _fstat(int file, struct stat *st)
|
||||
{
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
int _stat (const char *fname, struct stat *st)
|
||||
{
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifndef NO_FILE
|
||||
int _link (void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _unlink (void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
void _raise (void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef NO_TIME
|
||||
|
||||
int _gettimeofday (struct timeval * tp, struct timezone * tzp)
|
||||
{
|
||||
|
||||
if (tp)
|
||||
{
|
||||
/* Ask the host for the seconds since the Unix epoch. */
|
||||
{
|
||||
int value;
|
||||
asm ("swi %a1; mov %0, r0" : "=r" (value): "i" (SWI_Time) : "r0");
|
||||
tp->tv_sec = value;
|
||||
}
|
||||
tp->tv_usec = 0;
|
||||
}
|
||||
|
||||
/* Return fixed data for the timezone. */
|
||||
if (tzp)
|
||||
{
|
||||
tzp->tz_minuteswest = 0;
|
||||
tzp->tz_dsttime = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Return a clock that ticks at 100Hz. */
|
||||
clock_t _times (struct tms * tp)
|
||||
{
|
||||
clock_t timeval;
|
||||
|
||||
asm ("swi %a1; mov %0, r0" : "=r" (timeval): "i" (SWI_Clock) : "r0");
|
||||
|
||||
if (tp)
|
||||
{
|
||||
tp->tms_utime = timeval; /* user time */
|
||||
tp->tms_stime = 0; /* system time */
|
||||
tp->tms_cutime = 0; /* user time, children */
|
||||
tp->tms_cstime = 0; /* system time, children */
|
||||
}
|
||||
|
||||
return timeval;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
int isatty (int fd)
|
||||
{
|
||||
return 1;
|
||||
fd = fd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _system (const char *s)
|
||||
{
|
||||
if (s == NULL)
|
||||
return 0;
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
#ifndef NO_FILE
|
||||
|
||||
int _rename (const char * oldpath, const char * newpath)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
254
cpu/stm32w108/e_stdio/src/test.c
Normal file
254
cpu/stm32w108/e_stdio/src/test.c
Normal file
|
@ -0,0 +1,254 @@
|
|||
|
||||
#include "UART0_stdio.h"
|
||||
|
||||
int main() {
|
||||
|
||||
char ent_char ;
|
||||
int ent_dec_pos ;
|
||||
int ent_dec_neg ;
|
||||
int ent_hex ;
|
||||
int ent_oct ;
|
||||
int ent_oct_hex ;
|
||||
long ent_slong ;
|
||||
unsigned short ent_ushort ;
|
||||
unsigned long ent_ulong ;
|
||||
char tab_char[3] ;
|
||||
|
||||
|
||||
char nom [50] ;
|
||||
char mois[50] ;
|
||||
int jour ;
|
||||
int annee ;
|
||||
int *ptr ;
|
||||
char tab[3] ;
|
||||
long double fld ;
|
||||
float flottant ;
|
||||
double f ;
|
||||
double f4 ;
|
||||
long double f1 ;
|
||||
float f2, f3 ;
|
||||
|
||||
|
||||
printf("Entrez un char:");
|
||||
scanf("%c" , &ent_char);
|
||||
printf("%c\n", ent_char);
|
||||
|
||||
|
||||
|
||||
printf("Entrez trois caracteres:\n");
|
||||
scanf("%3c" , tab_char);
|
||||
printf("1er char :%c\n", tab_char[0]);
|
||||
printf("2eme char :%c\n", tab_char[1]);
|
||||
printf("3eme char :%c\n", tab_char[2]);
|
||||
|
||||
printf("Entrez un nombre decimal positif: ");
|
||||
scanf("%d" , &ent_dec_pos);
|
||||
printf("%d\n", ent_dec_pos);
|
||||
|
||||
printf("Entrez un nombre decimal negatif: ");
|
||||
scanf("%d" , &ent_dec_neg);
|
||||
printf("%d\n", ent_dec_neg);
|
||||
|
||||
printf("Entrez un nombre decimal long: ");
|
||||
scanf("%ld" , &ent_slong);
|
||||
printf("%ld\n", ent_slong);
|
||||
|
||||
printf("Entrez un nombre decimal unsigned long: ");
|
||||
scanf("%lu" , &ent_ulong);
|
||||
printf("valeur entree: %lu\n", ent_ulong);
|
||||
|
||||
printf("Entrez un nombre decimal unsigned short: ");
|
||||
scanf("%hu" , &ent_ushort);
|
||||
printf("valeur entree: %lu\n", ent_ushort);
|
||||
|
||||
|
||||
printf("Entrez un nombre en hexa: ");
|
||||
scanf("%x" , &ent_hex);
|
||||
printf("%x\n", ent_hex);
|
||||
|
||||
printf("Entrez un nombre en octal: ");
|
||||
scanf("%o" , &ent_oct);
|
||||
printf("%o \n", ent_oct);
|
||||
|
||||
printf("Entrez un nombre en octal ou hexa (preceder de 0 pour octal et de 0x ou 0X pour hexa), ");
|
||||
scanf("%i" , &ent_oct_hex);
|
||||
printf("valeur entree en decimal : %i \n", ent_oct_hex);
|
||||
|
||||
printf("Entrez une chaine de caracteres: ");
|
||||
scanf("%s" , nom);
|
||||
printf("%s \n", nom);
|
||||
|
||||
printf("Entrez le jour,le mois et l'annee:\n");
|
||||
|
||||
scanf("%d%s%d", &jour, mois, &annee);
|
||||
printf("\njour:%d \n",jour);
|
||||
printf("mois:%s \n",mois);
|
||||
printf("annee:%d \n",annee);
|
||||
|
||||
|
||||
|
||||
// Dans le cas du format %[...] : le scanf se termine lorsqu'un caractere n'appartenant pas a
|
||||
// l'ensemble est detecte, inversement si on specifie %[^...] le scanf s'arrete lorsque'un
|
||||
//caractere de l'ensembles a ete lu
|
||||
|
||||
printf("Entrez une chaine de caracteres en majuscules: ");
|
||||
scanf("%[A-Z]" , nom);
|
||||
printf("%s \n", nom);
|
||||
|
||||
printf("Entrez une chaine de caracteres sans majuscules pour terminer le scanf entrez une majuscule: ");
|
||||
scanf("%[^A-Z]" , nom);
|
||||
printf("%s \n", nom);
|
||||
|
||||
printf("Entrez une adresse memoire quelconque \n");
|
||||
scanf("%p",&ptr);
|
||||
printf("L'adresse %p contient la valeur %d ",ptr,*ptr);
|
||||
|
||||
/* printf("Entrez un caractere: ");
|
||||
scanf("%c" , &ent_char);
|
||||
__io_ungetc(ent_char);
|
||||
scanf("%c" , &ent_char);
|
||||
printf("Apres un scanf suivi d'un ungetc et d'un scanf on a : %c \n", ent_char);
|
||||
|
||||
printf("Entrez une chaine de 2 caracteres\n ");
|
||||
scanf("%s" , nom);
|
||||
printf("la chaine entree est %s \n",nom);
|
||||
ent_char = __io_ungetc(nom[0]);
|
||||
scanf("%c" , nom[0]) ;
|
||||
printf("Apres un ungetc et d'un scanf on a : %s \n", nom);
|
||||
*/
|
||||
|
||||
printf("Entrer un float:\n");
|
||||
scanf("%f",&flottant);
|
||||
printf("Le float entre est %f",flottant);
|
||||
|
||||
printf("Entrer un double float:\n");
|
||||
scanf("%Lf",&f);
|
||||
printf("Le float entre est %Lf\n",f);
|
||||
|
||||
|
||||
printf("Entrer un nombre avec exposant :\n");
|
||||
scanf("%le",&f);
|
||||
printf("Le float entre est %le\n",f);
|
||||
|
||||
// Note : le format %g choisit en fonction de la valeur entree le format le plus
|
||||
// appropriée entre %e et %f
|
||||
|
||||
|
||||
printf("Entrer un nombre avec exposant :\n");
|
||||
scanf("%lg",&f);
|
||||
printf("Le float entre est %lg\n",f);
|
||||
|
||||
printf("Entrer un nombre avec exposant :\n");
|
||||
scanf("%Lg",&fld);
|
||||
printf("Le float entre est %Lg\n",fld);
|
||||
|
||||
|
||||
f1 = 48656568.256479123456789123456789;
|
||||
f = 48656568.256479123456789123456789;
|
||||
f2 = 456.45366;
|
||||
f3 = 456.45362;
|
||||
printf("Test for Floating points numbers printf\n");
|
||||
|
||||
/*Simple test of %f format */
|
||||
printf("double :%lf\n",f);
|
||||
|
||||
/* Test with format specifying first number is equal to minimal number
|
||||
of caracter to be print the second one is number of digits */
|
||||
|
||||
printf("LONG DOUBLE :%Lf - %20.10Lf - %20.15Lf - %20.20Lf - %30.30Lf\n", f1, f1, f1, f1, f1);
|
||||
printf("float2 :%4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
|
||||
|
||||
/*Note: the output should be float2: 3.14 +3e+000 3.141600E+000*/
|
||||
|
||||
printf("float3 :%7.3f\n", 1.2345);
|
||||
printf("float3bis :%7.3lf\n",4865.256479 );
|
||||
printf("float4 :%10.3f\n", 1.2345e3);
|
||||
printf("float5 :%10.3f\n", 1.2345e7);
|
||||
printf("float6 :%12.4e\n", 1.2345);
|
||||
printf("float7 :%12.4e\n", 123.456789e8);
|
||||
printf("float8 :%15.5lf\n",48656568.256479 );
|
||||
printf("float9 :%15.6lf\n",48656568.256479 - 48656568.256478 );
|
||||
printf("float9bis :%-15.6lf%7.4f\n",48656568.256479 - 48656568.256478,1.2345 );
|
||||
printf("float9ter :%15.2lf\n",f2*f3 );
|
||||
|
||||
/*Note : the outputs shoud be
|
||||
for 1.2345, ^^1.235
|
||||
for 1.2345e5, ^^1234.500
|
||||
for 1.2345e7, 12345000.000
|
||||
for 1.2345, ^^1.2345e+00
|
||||
for 123.456789e8, ^^1.2346e+10
|
||||
|
||||
for float 9: 48656568.256479 - 48656568.2563,^^^^^^^^0.00001
|
||||
for float 9bis: 48656568.256479 - 48656568.2563,0.00001^^^^^^^^1.2345
|
||||
for f2*f3 ,^^^^^^208349,92
|
||||
^ is equal to a space */
|
||||
|
||||
|
||||
printf("float10 :01234567 \n" );
|
||||
printf("float11 :%8g|\n", 12.34 );
|
||||
printf("float12 :%8g|\n", 1234.5678 );
|
||||
printf("float13 :%8g|\n", 0.0478 );
|
||||
printf("float14 :%8g|\n", 422121.0 );
|
||||
printf("float15 :%8g|\n", 422121234.345345 );
|
||||
|
||||
/*Note : outputs should be
|
||||
01234567
|
||||
12.34|
|
||||
1234.57|
|
||||
0.0478|
|
||||
422121|
|
||||
4.22121e+08|
|
||||
*/
|
||||
|
||||
|
||||
printf("float16 :%.0f|\n", 1000.123456789123456789 );
|
||||
printf("float17 :%.1f|\n", 2000.123456789123456789 );
|
||||
printf("float18 :%.2f|\n", 3000.123456789123456789 );
|
||||
printf("float19 :%.10f|\n", 4000.123456789123456789 );
|
||||
printf("float20 :%.30f|\n", 5000.123456789123456789 );
|
||||
printf("float21 :%f|\n", 6000.123456789123456789 );
|
||||
printf("float22 :%.f|\n", 7000.123456789123456789 );
|
||||
|
||||
/*Note : outputs should be
|
||||
1000|
|
||||
2000.1|
|
||||
3000.12|
|
||||
4000.1234567891|
|
||||
5000.12345678912333823973312939761|
|
||||
6000.123457|
|
||||
7000|
|
||||
*/
|
||||
|
||||
int a ;
|
||||
char c ;
|
||||
float ft ;
|
||||
int hex ;
|
||||
double db ;
|
||||
char stg[50]="chaine" ;
|
||||
|
||||
a=1;
|
||||
// Test du printf avec une suite de parametres int
|
||||
printf("Test suite de int: \n a=%d\na+1=%d\na+2=%d\na+3=%d\na+4=%d\na+5=%d\na+6=%d\na+7=%d\na+8=%d\na=%d\n",a,a+1,a+2,a+3,a+4,a+5,a+6,a+7,a+8,a);
|
||||
|
||||
//Test du printf avec une suite de floats
|
||||
ft=1.589634 ;
|
||||
printf("Test suite de floats: \nft=%f\nft+0.1=%f\nft+0.01=%f\nft+0.001=%f\nft+0.0001=%f\nft+0.00001=%f\n",ft,ft+0.1,ft+0.01,ft+0.001,ft+0.0001,ft+0.00001);
|
||||
|
||||
// Test du printf avec un melange de formats
|
||||
|
||||
a = 1 ;
|
||||
c ='c' ;
|
||||
ft = 1.963214 ;
|
||||
db = 1.589e+15;
|
||||
hex = 0x0FA ;
|
||||
|
||||
printf("Test avec plusieurs formats:\na=%d\nc=%c\nstg=%s\nft=%6.5f\ndb=%10.2e\nhex=%x\n",a,c,stg,ft,db,hex);
|
||||
printf("Entrez dans l'ordre un int\n un char\n une chaine\nun float\nun float avec exposant\nun hexa \n");
|
||||
scanf("%d%c%s%f%le%x",&a,&c,stg,&ft,&db,&hex);
|
||||
printf("Test avec plusieurs formats apres un scanf:\n a=%d\nc=%c\nstg=%s\nft=%6.5f\ndb=%10.2le\nhex=0x%x\n",a,c,stg,ft,db,hex);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
44
cpu/stm32w108/e_stdio/src/test_mes.c
Normal file
44
cpu/stm32w108/e_stdio/src/test_mes.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
|
||||
#define FLOATING
|
||||
#define PRINT
|
||||
#define SCANF
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
char ent_char ;
|
||||
float flottant ;
|
||||
|
||||
#ifndef FLOATING
|
||||
#ifdef PRINT
|
||||
ent_char='a';
|
||||
#endif
|
||||
|
||||
#ifdef SCANF
|
||||
scanf("%c" , &ent_char);
|
||||
#endif
|
||||
|
||||
#ifdef PRINT
|
||||
printf("%c\n", ent_char);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#else
|
||||
#ifdef PRINT
|
||||
flottant = 1.456789;
|
||||
#endif
|
||||
|
||||
#ifdef SCANF
|
||||
scanf("%f" , &flottant);
|
||||
#endif
|
||||
|
||||
#ifdef PRINT
|
||||
printf("%f\n", flottant);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
87
cpu/stm32w108/e_stdio/src/test_printf.c
Normal file
87
cpu/stm32w108/e_stdio/src/test_printf.c
Normal file
|
@ -0,0 +1,87 @@
|
|||
|
||||
int main (){
|
||||
double f;
|
||||
|
||||
/*double f4;
|
||||
long double f1;
|
||||
float f2, f3;
|
||||
float flottant;*/
|
||||
|
||||
f = 48656568.256479123456789123456789;
|
||||
/*
|
||||
f1= 48656568.256479123456789123456789;
|
||||
f2 = 456.45366;
|
||||
f3 = 456.45362; */
|
||||
//printf("Test du printf");
|
||||
|
||||
/*Simple test of %f format */
|
||||
printf("double :%lf\n",f);
|
||||
|
||||
/* Test with format specifying first number is equal to minimal number
|
||||
of caracter to be print the second one is number of digits */
|
||||
/*
|
||||
printf("LONG DOUBLE :%Lf - %20.10Lf - %20.15Lf - %20.20Lf - %30.30Lf\n", f1, f1, f1, f1, f1);
|
||||
printf("float2 :%4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);*/
|
||||
|
||||
/*Note: the output should be float2: 3.14 +3e+000 3.141600E+000*/
|
||||
/*
|
||||
printf("float3 :%7.3f\n", 1.2345);
|
||||
printf("float3bis :%7.3lf\n",4865.256479 );
|
||||
printf("float4 :%10.3f\n", 1.2345e3);
|
||||
printf("float5 :%10.3f\n", 1.2345e7);
|
||||
printf("float6 :%12.4e\n", 1.2345);
|
||||
printf("float7 :%12.4e\n", 123.456789e8);
|
||||
printf("float8 :%15.5lf\n",48656568.256479 );
|
||||
printf("float9 :%15.6lf\n",48656568.256479 - 48656568.256478 );
|
||||
printf("float9bis :%15.2lf\n",f2*f3 );*/
|
||||
/*Note : the outputs shoud be
|
||||
for 1.2345, ^^1.235
|
||||
for 1.2345e5, ^^1234.500
|
||||
for 1.2345e7, 12345000.000
|
||||
for 1.2345, ^^1.2345e+00
|
||||
for 123.456789e8, ^^1.2346e+10
|
||||
for 48656568.256479 - 48656568.2563,^^^^^^^^0.00001
|
||||
for f2*f3 ,^^^^^^208349,92
|
||||
^ is equal to a space */
|
||||
|
||||
/*
|
||||
printf("float10 :01234567 \n" );
|
||||
printf("float11 :%8g|\n", 12.34 );
|
||||
printf("float12 :%8g|\n", 1234.5678 );
|
||||
printf("float13 :%8g|\n", 0.0478 );
|
||||
printf("float14 :%8g|\n", 422121.0 );
|
||||
printf("float15 :%8g|\n", 422121234.345345 );*/
|
||||
/*Note : outputs should be
|
||||
01234567
|
||||
12.34|
|
||||
1234.57|
|
||||
0.0478|
|
||||
422121|
|
||||
4.22121e+08|
|
||||
*/
|
||||
/*
|
||||
|
||||
printf("float16 :%.0f|\n", 1000.123456789123456789 );
|
||||
printf("float17 :%.1f|\n", 2000.123456789123456789 );
|
||||
printf("float18 :%.2f|\n", 3000.123456789123456789 );
|
||||
printf("float19 :%.10f|\n", 4000.123456789123456789 );
|
||||
printf("float20 :%.30f|\n", 5000.123456789123456789 );
|
||||
printf("float21 :%f|\n", 6000.123456789123456789 );
|
||||
printf("float22 :%.f|\n", 7000.123456789123456789 );
|
||||
*/
|
||||
/*Note : outputs should be
|
||||
1000|
|
||||
2000.1|
|
||||
3000.12|
|
||||
4000.1234567891|
|
||||
5000.12345678912333823973312939761|
|
||||
6000.123457|
|
||||
7000|
|
||||
*/
|
||||
|
||||
|
||||
//while(1);
|
||||
|
||||
}
|
||||
|
||||
|
14
cpu/stm32w108/e_stdio/src/test_scanf.c
Normal file
14
cpu/stm32w108/e_stdio/src/test_scanf.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
float flottant ;
|
||||
// char c;
|
||||
scanf("%f" , &flottant);
|
||||
// scanf("%c",&c);
|
||||
//while(1);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
284
cpu/stm32w108/e_stdio/src/vfieeefp.h
Normal file
284
cpu/stm32w108/e_stdio/src/vfieeefp.h
Normal file
|
@ -0,0 +1,284 @@
|
|||
/****************************************************************
|
||||
*
|
||||
* The author of this software is David M. Gay.
|
||||
*
|
||||
* Copyright (c) 1991 by AT&T.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose without fee is hereby granted, provided that this entire notice
|
||||
* is included in all copies of any software which is or includes a copy
|
||||
* or modification of this software and in all copies of the supporting
|
||||
* documentation for such software.
|
||||
*
|
||||
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
|
||||
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY
|
||||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
||||
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
||||
*
|
||||
***************************************************************/
|
||||
|
||||
/* Please send bug reports to
|
||||
David M. Gay
|
||||
AT&T Bell Laboratories, Room 2C-463
|
||||
600 Mountain Avenue
|
||||
Murray Hill, NJ 07974-2070
|
||||
U.S.A.
|
||||
dmg@research.att.com or research!dmg
|
||||
*/
|
||||
|
||||
/* This header file is a modification of mprec.h that only contains floating
|
||||
point union code. */
|
||||
|
||||
#include <ieeefp.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <errno.h>
|
||||
#include <sys/config.h>
|
||||
|
||||
#ifdef __IEEE_LITTLE_ENDIAN
|
||||
#define IEEE_8087
|
||||
#endif
|
||||
|
||||
#ifdef __IEEE_BIG_ENDIAN
|
||||
#define IEEE_MC68k
|
||||
#endif
|
||||
|
||||
#ifdef __Z8000__
|
||||
#define Just_16
|
||||
#endif
|
||||
|
||||
#ifdef Unsigned_Shifts
|
||||
#define Sign_Extend(a,b) if (b < 0) a |= (__uint32_t)0xffff0000;
|
||||
#else
|
||||
#define Sign_Extend(a,b) /*no-op*/
|
||||
#endif
|
||||
|
||||
#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
|
||||
Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
|
||||
#endif
|
||||
|
||||
#ifdef WANT_IO_LONG_DBL
|
||||
/* If we are going to examine or modify specific bits in a long double using
|
||||
the lword0 or lwordx macros, then we must wrap the long double inside
|
||||
a union. This is necessary to avoid undefined behavior according to
|
||||
the ANSI C spec. */
|
||||
|
||||
#ifdef IEEE_8087
|
||||
#if LDBL_MANT_DIG == 24
|
||||
struct ldieee
|
||||
{
|
||||
unsigned manh:23;
|
||||
unsigned exp:8;
|
||||
unsigned sign:1;
|
||||
};
|
||||
#elif LDBL_MANT_DIG == 53
|
||||
struct ldieee
|
||||
{
|
||||
unsigned manl:20;
|
||||
unsigned manh:32;
|
||||
unsigned exp:11;
|
||||
unsigned sign:1;
|
||||
};
|
||||
#elif LDBL_MANT_DIG == 64
|
||||
struct ldieee
|
||||
{
|
||||
unsigned manl:32;
|
||||
unsigned manh:32;
|
||||
unsigned exp:15;
|
||||
unsigned sign:1;
|
||||
};
|
||||
#elif LDBL_MANT_DIG > 64
|
||||
struct ldieee
|
||||
{
|
||||
unsigned manl3:16;
|
||||
unsigned manl2:32;
|
||||
unsigned manl:32;
|
||||
unsigned manh:32;
|
||||
unsigned exp:15;
|
||||
unsigned sign:1;
|
||||
};
|
||||
#endif /* LDBL_MANT_DIG */
|
||||
#else /* !IEEE_8087 */
|
||||
#if LDBL_MANT_DIG == 24
|
||||
struct ldieee
|
||||
{
|
||||
unsigned sign:1;
|
||||
unsigned exp:8;
|
||||
unsigned manh:23;
|
||||
};
|
||||
#elif LDBL_MANT_DIG == 53
|
||||
struct ldieee
|
||||
{
|
||||
unsigned sign:1;
|
||||
unsigned exp:11;
|
||||
unsigned manh:32;
|
||||
unsigned manl:20;
|
||||
};
|
||||
#elif LDBL_MANT_DIG == 64
|
||||
struct ldieee
|
||||
{
|
||||
unsigned sign:1;
|
||||
unsigned exp:15;
|
||||
unsigned manh:32;
|
||||
unsigned manl:32;
|
||||
};
|
||||
#elif LDBL_MANT_DIG > 64
|
||||
struct ldieee
|
||||
{
|
||||
unsigned sign:1;
|
||||
unsigned exp:15;
|
||||
unsigned manh:32;
|
||||
unsigned manl:32;
|
||||
unsigned manl2:32;
|
||||
unsigned manl3;16;
|
||||
};
|
||||
#endif /* LDBL_MANT_DIG */
|
||||
#endif /* !IEEE_8087 */
|
||||
#endif /* WANT_IO_LONG_DBL */
|
||||
|
||||
/* If we are going to examine or modify specific bits in a double using
|
||||
the word0 and/or word1 macros, then we must wrap the double inside
|
||||
a union. This is necessary to avoid undefined behavior according to
|
||||
the ANSI C spec. */
|
||||
union double_union
|
||||
{
|
||||
double d;
|
||||
__uint32_t i[2];
|
||||
};
|
||||
|
||||
#ifdef IEEE_8087
|
||||
#define word0(x) (x.i[1])
|
||||
#define word1(x) (x.i[0])
|
||||
#else
|
||||
#define word0(x) (x.i[0])
|
||||
#define word1(x) (x.i[1])
|
||||
#endif
|
||||
|
||||
/* #define P DBL_MANT_DIG */
|
||||
/* Ten_pmax = floor(P*log(2)/log(5)) */
|
||||
/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
|
||||
/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
|
||||
/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
|
||||
|
||||
#if defined(IEEE_8087) + defined(IEEE_MC68k)
|
||||
#if defined (_DOUBLE_IS_32BITS)
|
||||
#define Exp_shift 23
|
||||
#define Exp_shift1 23
|
||||
#define Exp_msk1 ((__uint32_t)0x00800000L)
|
||||
#define Exp_msk11 ((__uint32_t)0x00800000L)
|
||||
#define Exp_mask ((__uint32_t)0x7f800000L)
|
||||
#define P 24
|
||||
#define Bias 127
|
||||
#if 0
|
||||
#define IEEE_Arith /* it is, but the code doesn't handle IEEE singles yet */
|
||||
#endif
|
||||
#define Emin (-126)
|
||||
#define Exp_1 ((__uint32_t)0x3f800000L)
|
||||
#define Exp_11 ((__uint32_t)0x3f800000L)
|
||||
#define Ebits 8
|
||||
#define Frac_mask ((__uint32_t)0x007fffffL)
|
||||
#define Frac_mask1 ((__uint32_t)0x007fffffL)
|
||||
#define Ten_pmax 10
|
||||
#define Sign_bit ((__uint32_t)0x80000000L)
|
||||
#define Ten_pmax 10
|
||||
#define Bletch 2
|
||||
#define Bndry_mask ((__uint32_t)0x007fffffL)
|
||||
#define Bndry_mask1 ((__uint32_t)0x007fffffL)
|
||||
#define LSB 1
|
||||
#define Sign_bit ((__uint32_t)0x80000000L)
|
||||
#define Log2P 1
|
||||
#define Tiny0 0
|
||||
#define Tiny1 1
|
||||
#define Quick_max 5
|
||||
#define Int_max 6
|
||||
#define Infinite(x) (word0(x) == ((__uint32_t)0x7f800000L))
|
||||
#undef word0
|
||||
#undef word1
|
||||
|
||||
#define word0(x) (x.i[0])
|
||||
#define word1(x) 0
|
||||
#else
|
||||
|
||||
#define Exp_shift 20
|
||||
#define Exp_shift1 20
|
||||
#define Exp_msk1 ((__uint32_t)0x100000L)
|
||||
#define Exp_msk11 ((__uint32_t)0x100000L)
|
||||
#define Exp_mask ((__uint32_t)0x7ff00000L)
|
||||
#define P 53
|
||||
#define Bias 1023
|
||||
#define IEEE_Arith
|
||||
#define Emin (-1022)
|
||||
#define Exp_1 ((__uint32_t)0x3ff00000L)
|
||||
#define Exp_11 ((__uint32_t)0x3ff00000L)
|
||||
#define Ebits 11
|
||||
#define Frac_mask ((__uint32_t)0xfffffL)
|
||||
#define Frac_mask1 ((__uint32_t)0xfffffL)
|
||||
#define Ten_pmax 22
|
||||
#define Bletch 0x10
|
||||
#define Bndry_mask ((__uint32_t)0xfffffL)
|
||||
#define Bndry_mask1 ((__uint32_t)0xfffffL)
|
||||
#define LSB 1
|
||||
#define Sign_bit ((__uint32_t)0x80000000L)
|
||||
#define Log2P 1
|
||||
#define Tiny0 0
|
||||
#define Tiny1 1
|
||||
#define Quick_max 14
|
||||
#define Int_max 14
|
||||
#define Infinite(x) (word0(x) == ((__uint32_t)0x7ff00000L)) /* sufficient test for here */
|
||||
#endif
|
||||
|
||||
#else
|
||||
#undef Sudden_Underflow
|
||||
#define Sudden_Underflow
|
||||
#ifdef IBM
|
||||
#define Exp_shift 24
|
||||
#define Exp_shift1 24
|
||||
#define Exp_msk1 ((__uint32_t)0x1000000L)
|
||||
#define Exp_msk11 ((__uint32_t)0x1000000L)
|
||||
#define Exp_mask ((__uint32_t)0x7f000000L)
|
||||
#define P 14
|
||||
#define Bias 65
|
||||
#define Exp_1 ((__uint32_t)0x41000000L)
|
||||
#define Exp_11 ((__uint32_t)0x41000000L)
|
||||
#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */
|
||||
#define Frac_mask ((__uint32_t)0xffffffL)
|
||||
#define Frac_mask1 ((__uint32_t)0xffffffL)
|
||||
#define Bletch 4
|
||||
#define Ten_pmax 22
|
||||
#define Bndry_mask ((__uint32_t)0xefffffL)
|
||||
#define Bndry_mask1 ((__uint32_t)0xffffffL)
|
||||
#define LSB 1
|
||||
#define Sign_bit ((__uint32_t)0x80000000L)
|
||||
#define Log2P 4
|
||||
#define Tiny0 ((__uint32_t)0x100000L)
|
||||
#define Tiny1 0
|
||||
#define Quick_max 14
|
||||
#define Int_max 15
|
||||
#else /* VAX */
|
||||
#define Exp_shift 23
|
||||
#define Exp_shift1 7
|
||||
#define Exp_msk1 0x80
|
||||
#define Exp_msk11 ((__uint32_t)0x800000L)
|
||||
#define Exp_mask ((__uint32_t)0x7f80L)
|
||||
#define P 56
|
||||
#define Bias 129
|
||||
#define Exp_1 ((__uint32_t)0x40800000L)
|
||||
#define Exp_11 ((__uint32_t)0x4080L)
|
||||
#define Ebits 8
|
||||
#define Frac_mask ((__uint32_t)0x7fffffL)
|
||||
#define Frac_mask1 ((__uint32_t)0xffff007fL)
|
||||
#define Ten_pmax 24
|
||||
#define Bletch 2
|
||||
#define Bndry_mask ((__uint32_t)0xffff007fL)
|
||||
#define Bndry_mask1 ((__uint32_t)0xffff007fL)
|
||||
#define LSB ((__uint32_t)0x10000L)
|
||||
#define Sign_bit ((__uint32_t)0x8000L)
|
||||
#define Log2P 1
|
||||
#define Tiny0 0x80
|
||||
#define Tiny1 0
|
||||
#define Quick_max 15
|
||||
#define Int_max 15
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue