Mes C Library: m2/ntoab.c: Remove specialization.
* lib/mes/ntoab.c (__mesabi_uldiv)[__M2_PLANET__ || !(__MESC__ && __arm__)]: New function. * lib/mes/ntoab.c (ntoab): Use it to cater for M2-Planet. * lib/m2/ntoab.c: Remove. * kaem.run: Update accordingly. * simple.make (M2_SOURCES, (M2_TODO): Likewise.
This commit is contained in:
parent
f7e772d7e0
commit
a4e56aac56
4
kaem.run
4
kaem.run
|
@ -1,5 +1,5 @@
|
|||
#! /bin/sh
|
||||
# Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
# Copyright © 2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
#
|
||||
# This file is part of GNU Mes.
|
||||
#
|
||||
|
@ -63,7 +63,7 @@ M2-Planet \
|
|||
-f lib/string/strncmp.c \
|
||||
-f lib/posix/getenv.c \
|
||||
-f lib/mes/fdputs.c \
|
||||
-f lib/m2/ntoab.c \
|
||||
-f lib/mes/ntoab.c \
|
||||
-f lib/ctype/isdigit.c \
|
||||
-f lib/ctype/isxdigit.c \
|
||||
-f lib/ctype/isspace.c \
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* GNU Mes is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
char *__itoa_buf;
|
||||
|
||||
char *
|
||||
ntoab (long x, int base, int signed_p)
|
||||
{
|
||||
if (__itoa_buf == 0)
|
||||
__itoa_buf = malloc (20);
|
||||
|
||||
char *buf = __itoa_buf;
|
||||
char *p = buf + 11;
|
||||
p[0] = 0;
|
||||
p = p - 1;
|
||||
assert_msg (base > 0, "base > 0");
|
||||
|
||||
int sign_p = 0;
|
||||
unsigned u;
|
||||
unsigned i;
|
||||
if (signed_p != 0 && x < 0)
|
||||
{
|
||||
sign_p = 1;
|
||||
u = -x;
|
||||
}
|
||||
else
|
||||
u = x;
|
||||
|
||||
do
|
||||
{
|
||||
i = u % base;
|
||||
u = u / base;
|
||||
if (i > 9)
|
||||
p[0] = 'a' + i - 10;
|
||||
else
|
||||
p[0] = '0' + i;
|
||||
p = p - 1;
|
||||
}
|
||||
while (u != 0);
|
||||
|
||||
if (sign_p && p[1] != '0')
|
||||
{
|
||||
p[0] = '-';
|
||||
p = p - 1;
|
||||
}
|
||||
|
||||
return p + 1;
|
||||
}
|
|
@ -23,45 +23,45 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if __M2_PLANET__ || !(__MESC__ && __arm__)
|
||||
size_t
|
||||
__mesabi_uldiv (size_t a, size_t b, size_t *remainder)
|
||||
{
|
||||
remainder[0] = a % b;
|
||||
return a / b;
|
||||
}
|
||||
#endif
|
||||
|
||||
char *__itoa_buf;
|
||||
|
||||
char *
|
||||
ntoab (long x, unsigned base, int signed_p)
|
||||
{
|
||||
#if 0
|
||||
if (! __itoa_buf)
|
||||
if (__itoa_buf == 0)
|
||||
__itoa_buf = malloc (20);
|
||||
p = __itoa_buf + 11;
|
||||
#else
|
||||
static char buf[20];
|
||||
char *p = buf + 19;
|
||||
#endif
|
||||
char *p = __itoa_buf + 11;
|
||||
|
||||
p[0] = 0;
|
||||
p = p - 1;
|
||||
assert_msg (base > 0, "base > 0");
|
||||
|
||||
int sign_p = 0;
|
||||
unsigned long u;
|
||||
size_t i;
|
||||
size_t u;
|
||||
size_t b = base;
|
||||
if (signed_p != 0 && x < 0)
|
||||
{
|
||||
sign_p = 1;
|
||||
/* Avoid LONG_MIN */
|
||||
u = (unsigned long) (-(x + 1));
|
||||
++u;
|
||||
u = (-(x + 1));
|
||||
u = u + 1;
|
||||
}
|
||||
else
|
||||
u = x;
|
||||
|
||||
do
|
||||
{
|
||||
unsigned long i;
|
||||
#if __MESC__ && __arm__
|
||||
u = __mesabi_uldiv (u, (unsigned long) base, &i);
|
||||
#else
|
||||
i = u % base;
|
||||
u = u / base;
|
||||
#endif
|
||||
u = __mesabi_uldiv (u, b, &i);
|
||||
if (i > 9)
|
||||
p[0] = 'a' + i - 10;
|
||||
else
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# GNU Mes --- Maxwell Equations of Software
|
||||
# Copyright © 2019 Jeremiah Orians <jeremiah@pdp10.guru>
|
||||
# Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
# Copyright © 2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
#
|
||||
# This file is part of GNU Mes.
|
||||
#
|
||||
|
@ -102,7 +102,7 @@ M2_SOURCES = \
|
|||
lib/string/strncmp.c \
|
||||
lib/posix/getenv.c \
|
||||
lib/mes/fdputs.c \
|
||||
lib/m2/ntoab.c \
|
||||
lib/mes/ntoab.c \
|
||||
lib/ctype/isdigit.c \
|
||||
lib/ctype/isxdigit.c \
|
||||
lib/ctype/isspace.c \
|
||||
|
@ -139,7 +139,7 @@ M2_SOURCES = \
|
|||
|
||||
M2_TODO = \
|
||||
lib/m2/file_print.c \
|
||||
lib/m2/ntoab.c \
|
||||
lib/mes/ntoab.c \
|
||||
lib/mes/fdgetc.c \
|
||||
lib/mes/fdungetc.c
|
||||
|
||||
|
|
Loading…
Reference in a new issue