Compare commits

...

52 Commits

Author SHA1 Message Date
Danny Milosavljevic 16ee8eb645
Add missing #include.
* lib/stdlib/mbstowcs.c: Add missing #include.
2019-09-21 00:04:45 +02:00
Danny Milosavljevic b3678c926f
Add missing #include.
* lib/stdio/vfscanf.c: Add missing #include.
2019-09-21 00:04:45 +02:00
Danny Milosavljevic f32f119eb2
Fix dtoab.
* lib/mes/dtoab.c (dtoab): Fix it.
* lib/tests/mes/90-dtoab.c (main): Fix test.
* build-aux/check-mescc.sh (XFAIL_TESTS: Remove it.
2019-09-21 00:04:45 +02:00
Danny Milosavljevic 98dc843da1
va_align: Fix compiler warning.
Follow-up to 49b0cd7d2e6952044d7436260d6ba950e40ee05f.

* include/stdarg.h: Fix compiler warning.
2019-09-21 00:04:45 +02:00
Danny Milosavljevic f9b9cc92e8
Add missing #include.
* lib/tests/mes/90-abtod.c (main): Add missing #include.
2019-09-21 00:04:45 +02:00
Danny Milosavljevic 0e6ee37ae2
Fix variable argument list traversal for doubles.
* include/stdarg.h (va_align): New macro.
(va_arg8): New macro.
* lib/stdio/vfprintf.c (vfprintf): Use it.
* lib/stdio/vsnprintf.c (vsnprintf): Use it.
2019-09-21 00:04:44 +02:00
Jan Nieuwenhuizen 7179559203
build: Improve --with-system-libc support.
* build-aux/build-lib.sh: Avoid building libc for --with-system-libc.
Make libmes richer.
build-aux/check-mescc.sh: Enable 50-malloc test.
* include/dirstream.h: Use HAVE_DIRSTREAM_H to cater for non-existing
dirstream.h.
* include/grp.h[SYSTEM_LIBC]: Typo.
* include/mes/lib.h (__brk, __call_at_exit)[SYSTEM_LIBC]: Declare.
* include/stdlib.h (comparison_fn_t)[SYSTEM_LIBC]: Declare.
* include/time.h (mktime): Return time_t.
* lib/posix/isatty.c [SYSTEM_LIBC]: Do not (re)declare termios.
* lib/stub/mktime.c (mktime): Return time_t.
* lib/tests/scaffold/41-ternary.c (main): Remove assumption that
locals are initialized.
* lib/tests/scaffold/70-stdarg.c: Cater for SYSTEM_LIBC.
* lib/tests/setjmp/80-setjmp.c: Declare jmp buf.
* lib/*/*.c: Add missing mes/lib.h, errno.h includes.
2019-09-21 00:04:44 +02:00
Jan Nieuwenhuizen 575debe0cd
mescc: Mes C Library: Support gcc-4.6.4: vsscanf: Support *, [, s.
* lib/stdio/vsscanf.c (vsscanf): Support  *, [, s.
* lib/stdio/vfscanf.c (vfscanf): Likewise.
* lib/tests/stdio/90-sscanf.c: Test it.
* build-aux/check-mescc.sh (tests): Run it.
* lib/x86-mes/x86.M1 (mov____%al,0x32(%ebp): New macro.
2019-09-21 00:04:44 +02:00
Jan Nieuwenhuizen 0a39884f85
mescc: Mes C Library: Support gcc-4.6.4: Allow larger qsort entries.
* lib/stdlib/qsort.c (qswap): Increase buffer to 128 bytes (gmp needs
36) and add assert.
2019-09-21 00:04:44 +02:00
Jan Nieuwenhuizen da4a692d72
mescc: Mes C Library: Support gcc-4.6.4: Avoid type/size_t conflicts.
* include/alloca.h: Remove typedefs, include sys/types.h.
* include/stdint.h: Likewise.
* include/string.h: Likewise.
2019-09-21 00:04:44 +02:00
Jan Nieuwenhuizen d25ec68b90
mescc: Mes C Library: Support gcc-4.6.4: Add strtok.
* include/string.h (strtok): Declare.
* lib/string/strtok.c (strtok): New file.
* lib/libc+gnu.c: Include it.
2019-09-21 00:04:44 +02:00
Jan Nieuwenhuizen 8c50b4f00b
mescc: Mes C Library: Support gcc-4.6.4: Add mmap, munmap.
* include/linux/x86/syscall.h (SYS_mmap, SYS_munmap): New macro.
* include/linux/x86_64/syscall.h (SYS_mmap, SYS_munmap): New macro.
* include/sys/mman.h (MAP_SHARED, MAP_PRIVATE, MAP_ANONYMOUS,
MAP_POPULATE, MAP_ANON, MAP_FAILED): New macro.
(mmap, munmap): Declare.
* lib/linux/x86-mes-gcc/mes.c (_sys_call6): New function.
* lib/linux/x86-mes/mes.c (__sys_call6): New function.
(_sys_call6): New function.
* lib/linux/x86_64-mes-gcc/mes.c (_sys_call6): New function.
* lib/linux/x86_64-mes/mes.c (__sys_call): Cater for 6 syscall parameters.
(_sys_call6): New function.
* lib/x86-mes/x86.M1 (pop____%ebp): New macro.
* lib/x86_64-mes/x86_64.M1 (mov____0x8(%rbp),%r9): New macro.
* lib/linux/mmap.c: New file.
* lib/linux/munmap.c: New file.
* build-aux/configure-lib.sh (libc_gnu_SOURCES): Add them.
2019-09-21 00:04:43 +02:00
Jan Nieuwenhuizen 1a81258abc
mescc: Mes C Library: Support gcc-4.6.4: Add labs.
* lib/math/labs.c: New file.
* lib/libc+gnu.c: Include it.
* include/math.h (labs): Declare.
2019-09-21 00:04:43 +02:00
Jan Nieuwenhuizen 64f20e41c3
mescc: Mes C Library: Support gcc-4.6.4: Implement rewind.
* lib/stdio/rewind.c: Move from ../stub.  Implement.
* include/stdio.h (rewind): Declare.
* lib/libc+gnu.c: Update include.
* lib/libg.c: Update include.
* lib/stub/rewind.c: Remove.
2019-09-21 00:04:43 +02:00
Jan Nieuwenhuizen 46b708c13c
mescc: Mes C Library: Support gcc-4.6.4: Add asctime stub.
* lib/stub/asctime.c: New file.
* lib/libc+gnu.c: Include it.
* include/time.h (asctime): Declare.
2019-09-21 00:04:43 +02:00
Jan Nieuwenhuizen 07f61420f7
mescc: Mes C Library: Support gcc-4.6.4: vfprintf, vsnprintf: #-type.
* lib/stdio/vfprintf.c (vfprintf): Support #-type prefix.  Show whole
format upon error.
* lib/stdio/vsnprintf.c (vsnprintf): Likewise.
* lib/stdio/vfscanf.c (vfscanf): Show whole template upon error.
* lib/stdio/vsscanf.c (vsscanf): Likewise.
2019-09-21 00:04:43 +02:00
Jan Nieuwenhuizen 278bc6a10c
mescc: Mes C Library: Support gcc-4.6.4: vfprintf, vsnprintf: pad with space.
* lib/stdio/vfprintf.c (vfprintf): pad with space.
* lib/stdio/vsnprintf.c (vsnprintf): pad with space.
2019-09-21 00:04:43 +02:00
Jan Nieuwenhuizen 192ec66f1f
mescc: Mes C Library: Support gcc-4.6.4: atexit: return 0.
* lib/stdlib/atexit.c (atexit): return 0.
2019-09-21 00:04:43 +02:00
Jan Nieuwenhuizen 93544b5654
mescc: Mes C Library: Support gcc-4.6.4: Add SSIZE_MAX macro.
* include/stdint.h (SSIZE_MAX): New macro.
2019-09-21 00:04:42 +02:00
Jan Nieuwenhuizen b53362cabb
mescc: Mes C Library: Support gcc-4.6.4: Add math stubs.
* lib/math/ceil.c: New file.
* lib/math/floor.c: New file.
* lib/stub/atan2.c: New file.
* lib/stub/cos.c: New file.
* lib/stub/exp.c: New file.
* lib/stub/log.c: New file.
* lib/stub/modf.c: New file.
* lib/stub/pow.c: New file.
* lib/stub/sin.c: New file.
* lib/stub/sqrt.c: New file.
* lib/libc+gnu.c: Include them.
* include/math.h (atan2, ceil, cos, exp, fabs, floor, log, modf, pow,
sin, sqrt): Declare.
* lib/math/fabs.c: Update.
* lib/stub/ldexp.c: Update.
2019-09-21 00:04:42 +02:00
Jan Nieuwenhuizen a1c4d16ba6
mescc: Mes C Library: Support gcc-4.6.4: Add fscanf, vfscanf.
* lib/stdio/vfscanf.c: New file.
* lib/stdio/fscanf.c: New file.
* build-aux/configure-lib.sh (libc_gnu_SOURCES): Add them.
* include/stdio.h (fscanf): Declare.
* include/stdarg.h (vfscanf): Declare.
* lib/libc+gnu.c: Include them.
* lib/libg.c: Likewise.
* lib/stub/fscanf.c: Remove.
2019-09-21 00:04:42 +02:00
Jan Nieuwenhuizen 1f95b76f52
mescc: Mes C Library: vfprintf, vsnprintf: Pad floats with space.
* lib/stdio/vfprintf.c (vfprintf): Pad floats with space.
* lib/stdio/vsnprintf.c (vsnprintf): Pad floats with space.
* lib/tests/stdio/90-sprintf.c: Test it.
2019-09-21 00:04:42 +02:00
Jan Nieuwenhuizen 126d590441
mescc: Mes C Library: Support gcc-4.6.4: Add float macros.
* include/float.h (DBL_EPSILON, DBL_MANT_DIG, DBL_MAX, DBL_MIN,
FLT_RADIX, LDBL_EPSILON, LDBL_MANT_DIG, LDBL_MAX, LDBL_MIN): New
macro.
2019-09-21 00:04:42 +02:00
Jan Nieuwenhuizen f48e8c39ad
mescc: Mes C Library: Support gcc-4.6.4: Add stdint [U]SHRT macros.
* include/stdint.h (SHRT_MAX, SHRT_MIN, USHRT_MAX, USHRT_MIN): New
macro.
2019-09-21 00:04:42 +02:00
Jan Nieuwenhuizen 90c81a197b
mescc: Mes C Library: Support gcc-4.6.4: Fix ctime stub.
* lib/stub/ctime.c (ctime): Fix stub to avoid segfault upon use.
2019-09-21 00:04:42 +02:00
Jan Nieuwenhuizen e5487bf7cd
mescc: Mes C Library: Support gcc-4.6.4: Fix uintptr_t, add [u]intmax_t.
* include/stdint.h: Fix uintptr_t, add [u]intmax_t.
2019-09-21 00:04:41 +02:00
Jan Nieuwenhuizen e988800a2b
mescc: Mes C Library: vsscanf: Increase count for scanned float.
* lib/stdio/vsscanf.c (vsscanf): Increase count for scanned float.
2019-09-21 00:04:41 +02:00
Jan Nieuwenhuizen fe30e1cd84
mescc: Mes C Library: Support GNU Tar: Fix getpwnam, getpwuid stubs.
* lib/stub/getpwnam.c (getpwnam): Return pointer to static struct
passwd.
* lib/stub/getpwuid.c (getpwuid): Likewise.
2019-09-21 00:04:41 +02:00
Jan Nieuwenhuizen f9f6fe7a8f
mescc: Mes C Library: Support GNU Tar: Add getgrgid, getgrnam, setgrent stub.
* include/grp.h: New file.
* lib/stub/getgrgid.c: New file.
* lib/stub/getgrnam.c: New file.
* lib/stub/setgrent.c: New file.
* lib/libc+gnu.c: Include them.
2019-09-21 00:04:41 +02:00
Jan Nieuwenhuizen 1940ad7489
mescc: Mes C Library: Support GNU Awk: Add wchar_t.
* include/sys/types.h (wchar_t): New typedef.
2019-09-21 00:04:41 +02:00
Jan Nieuwenhuizen 71736518f6
mescc: Mes C Library: Support GNU Awk: Add getpgid, getpgrp stubs.
* include/unistd.h (getpgid, getpgrp): Declare.
* lib/stub/getpgid.c: New file.
* lib/stub/getpgrp.c: New file.
* lib/libc+gnu.c: Include them.
2019-09-21 00:04:41 +02:00
Jan Nieuwenhuizen 0eee745f2b
mescc: Mes C Library: Support GNU Tar: Add mktime stub, fix localtime stub.
* include/time.h (mktime): Declare.
* lib/stub/mktime.c: New stub.
* lib/libc+gnu.c: Include it.
* lib/stub/localtime.c (localtime): Return pointer to static struct
tm.  Avoids segfaults.
2019-09-21 00:04:41 +02:00
Jan Nieuwenhuizen 991067d94a
mescc: Mes C Library: Support GNU Tar: Add creat, mknod.
* include/linux/x86_64/syscall.h (SYS_mknod): New macro.
* include/linux/x86/syscall.h (SYS_mknod): New macro.
* lib/linux/mknod.c: New file.
* build-aux/configure-lib.sh (libc_gnu_SOURCES): Add it.
* include/sys/stat.h (mknod): Declare it.
* include/fcntl.h (creat): New macro.
2019-09-21 00:04:40 +02:00
Jan Nieuwenhuizen 4428190b82
mescc: Mes C Library: Support GNU Tar: Add missing defines.
* include/errno.h (ENXIO): New macro.
* include/sys/stat.h (S_IFIFO, S_ISFIFO): New macro.
2019-09-21 00:04:40 +02:00
Jan Nieuwenhuizen 4a5d750f0f
mescc: Mes C Library: Support GNU Bash: Add struct winsize.
* include/termio.h (struct winsize): New type.
2019-09-21 00:04:40 +02:00
Jan Nieuwenhuizen 6ae158b6e9
mescc: Mes C Library: Support GNU Awk: Implement atof.
* lib/stdlib/atoi.c: Update.
* lib/stdlib/atof.c: Rename from stub/atof.c; Implement.
* lib/libc+gnu.c: Update include.
* lib/libg.c: Update include.
2019-09-21 00:04:40 +02:00
Jan Nieuwenhuizen 25c3bf2756
mescc: Mes C Library: Support GNU Awk: Add dtoab, %f in vfprintf, vsnprintf.
* include/libmes.h (dtoab): Declare.
* lib/mes/ntoab.c (ntoab): Update.
* lib/mes/dtoab.c: New file.
* build-aux/configure-lib.sh (libmes_SOURCES, libc_tcc_SOURCES): Add
it.
* lib/tests/mes/90-dtoab.c: Test it.
* lib/tests/stdio/90-sprintf.c: Test it.
* build-aux/check-mescc.sh (tests): Run it, against...
* lib/tests/mes/90-dtoab.stdout: ...baseline.
* lib/stdio/vfprintf.c (vfprintf): Support %f, even more naive support
for %e, %E, %g, %G.
* lib/stdio/vsnprintf.c (vsnprintf): Likewise.
2019-09-21 00:04:40 +02:00
Jan Nieuwenhuizen 4f54771a23
mescc: Mes C Library: Support GNU Awk: Add abtod, implementing strtod.
* include/libmes.h (abtod): Declare.
* lib/mes/abtod.c: New file.
* build-aux/configure-lib.sh (libmes_SOURCES, libc_tcc_SOURCES): Add
it.
* lib/mes/abtol.c: Update.
* lib/stdlib/strtod.c: Use it to implement; move from stub/strtod.
* lib/tests/mes/90-abtod.c: Test it.
* lib/tests/mes/90-abtod.stdout: Baseline.
* build-aux/check-mescc.sh (tests): Run it.
2019-09-21 00:04:40 +02:00
Jan Nieuwenhuizen 0c01199a67
mescc: Mes C Library: Support GNU Awk: vsscanf: Support %f.
* lib/stdio/vsscanf.c (vsscanf): Support %f.
2019-09-21 00:04:39 +02:00
Jan Nieuwenhuizen db325bce0a
mescc: Mes C Library: Support GNU Awk: Do not flush std files.
* lib/stdio/fflush.c (fflush): Do not flush std files.
2019-09-21 00:04:39 +02:00
Jan Nieuwenhuizen 6d929d5f50
mescc: Mes C Library: Support GNU Awk: Add isgraph.
* lib/ctype/isgraph.c: New file.
* lib/libc+gnu.c: Include it.
* include/ctype.h: Add missing prototypes.
2019-09-21 00:04:39 +02:00
Jan Nieuwenhuizen 0114f18d07
mescc: Mes C Library: Support GNU Tar: Add readlink, readlink.
* lib/linux/gnu.c (readlink, symlink): New function.
* include/unistd.h (readlink, symlink): Declare.
* include/linux/x86/syscall.h (SYS_readlink, SYS_symlink): New macro.
* include/linux/x86_64/syscall.h (SYS_symlink, SYS_readlink): New
macro.
2019-09-21 00:04:39 +02:00
Jan Nieuwenhuizen ac6b3864cc
mescc: Mes C Library: Support GNU Tar: Add execlp.
* lib/posix/execl.c (vexec): New function.
(execl): Use it.
* lib/posix/execlp.c: New file.
* build-aux/configure-lib.sh (libc_tcc_SOURCES): Add it.
* lib/libc+gnu.c: Include it.
* include/unistd.h (execlp): Declare.
* lib/tests/posix/90-execlp.c: New file.
* lib/tests/posix/90-execlp.stdout: New file.
* build-aux/check-mescc.sh: Test it.
2019-09-21 00:04:39 +02:00
Jan Nieuwenhuizen 4833b3e310
mescc: Mes C Library: Fix compile warnings.
* include/stdlib.h (abort): Add prototype.
2019-09-21 00:04:39 +02:00
Jan Nieuwenhuizen b75e2cba64
mescc: Bump stack. WIP.
* scripts/mescc.in (MES_MAX_ARENA): Also set.
(MES_STACK): Bump to 10000000.
2019-09-21 00:04:32 +02:00
Jan Nieuwenhuizen 32bf13ab86
build: Split-out build-source-lib.sh from build-lib.sh.
* build-aux/build-lib.sh: Remove building of source lib.
* build-aux/build-source-lib.sh: New file.
* build-aux/build.sh.in: Invoke it.
* build-aux/bootstrap.sh.in: Likewise.
2019-09-21 00:04:32 +02:00
Jan Nieuwenhuizen 2ae56d18b5
build: Avoid tar --exclude=.
* build-aux/install.sh.in: Only use `tar --exclude=' if we also have .go
files compiled by Guile.
2019-09-20 19:44:30 +02:00
Jan Nieuwenhuizen 2e082e0d6c
build: mesar: Remove bashisms.
* scripts/mesar.in: Remove bashisms.
2019-09-20 19:44:30 +02:00
Jan Nieuwenhuizen 5de5853c76
configure.sh: Remove bashisms.
* configure.sh: Remove bashisms.  Fixes running with Gash 0.1.
2019-09-20 19:44:30 +02:00
Jan Nieuwenhuizen 9405075e09
Revert "nyacc: 0.86.0 compatibility stub. WIP"
This reverts commit 0183cc1c42437fda27196e27b490285a61d47f59.

While it works to run Nyacc 0.86.0, it breaks running Nyacc 0.93 and
up.  This would need more thought and work, adding a nyacc-compat
directory or so.  Seems not worth the effort right now.
2019-09-20 19:43:24 +02:00
Jan Nieuwenhuizen 8bed92b7bd
nyacc: 0.86.0 compatibility stub. WIP
* mes/module/nyacc/lang/c99/util.scm: 0.86.0 compatibility stub.
2019-09-20 19:42:50 +02:00
Jan Nieuwenhuizen 2d7c2f9791
doc: Post-release update.
* doc/announce/ANNOUNCE-0.20: Update.
* guix/git/mes.scm (mes): Update.
2019-09-20 19:42:50 +02:00
104 changed files with 2077 additions and 176 deletions

View File

@ -81,3 +81,15 @@ for c in $mes_SOURCES; do
done done
echo "CCLD src/mes" echo "CCLD src/mes"
$CC -nostdlib -o src/mes -L mescc-lib mescc-lib/crt1.o $objects -lc $CC -nostdlib -o src/mes -L mescc-lib mescc-lib/crt1.o $objects -lc
(
mkdir -p gcc-lib
cp config.sh gcc-lib
cd gcc-lib
compiler=gcc
if test -z "$srcdest"; then
srcdest=../
srcdir=../
fi
@SHELL@ ${srcdest}build-aux/build-source-lib.sh
)

View File

@ -79,26 +79,3 @@ cp libgetopt.a $mes_cpu-mes
if test -e libgetopt.s; then if test -e libgetopt.s; then
cp libgetopt.s $mes_cpu-mes cp libgetopt.s $mes_cpu-mes
fi fi
cp ${srcdest}lib/$mes_kernel/$mes_cpu-mes-$compiler/crt*.c $mes_cpu-mes
rm -f libc+gnu.c
cat > libc+gnu.c <<EOF
// Generated from Mes -- do not edit
// compiler: $compiler
// cpu: $mes_cpu
// bits: $mes_bits
// libc: $mes_libc
// kernel: $mes_kernel
// system: $mes_system
EOF
for c in $libc_gnu_SOURCES; do
echo "// $c" >> libc+gnu.c
cat ${srcdest}$c >> libc+gnu.c
echo >> libc+gnu.c
done
cp libc+gnu.c $mes_cpu-mes
cp ${srcdest}lib/libtcc1.c $mes_cpu-mes
cp ${srcdest}lib/posix/getopt.c $mes_cpu-mes/libgetopt.c

View File

@ -0,0 +1,53 @@
#! /bin/sh
# GNU Mes --- Maxwell Equations of Software
# Copyright © 2019 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/>.
set -e
if test "$V" = 2; then
set -x
fi
set -u
srcdest=${srcdest-}
. ${srcdest}build-aux/configure-lib.sh
mkdir -p $mes_cpu-mes
cp ${srcdest}lib/$mes_kernel/$mes_cpu-mes-$compiler/crt*.c $mes_cpu-mes
rm -f libc+gnu.c
cat > libc+gnu.c <<EOF
// Generated from Mes -- do not edit
// compiler: $compiler
// cpu: $mes_cpu
// bits: $mes_bits
// libc: $mes_libc
// kernel: $mes_kernel
// system: $mes_system
EOF
for c in $libc_gnu_SOURCES; do
echo "// $c" >> libc+gnu.c
cat ${srcdest}$c >> libc+gnu.c
echo >> libc+gnu.c
done
cp libc+gnu.c $mes_cpu-mes
cp ${srcdest}lib/libtcc1.c $mes_cpu-mes
cp ${srcdest}lib/posix/getopt.c $mes_cpu-mes/libgetopt.c

View File

@ -87,15 +87,15 @@ export CPPFLAGS
export LDFLAGS export LDFLAGS
export LIBS export LIBS
if test $compiler = gcc; then (
( mkdir -p gcc-lib
mkdir -p gcc-lib cp config.sh gcc-lib
cp config.sh gcc-lib cd gcc-lib
cd gcc-lib if test -z "$srcdest"; then
if test -z "$srcdest"; then srcdest=../
srcdest=../ srcdir=../
srcdir=../ fi
fi if test $compiler = gcc; then
CPPFLAGS=" CPPFLAGS="
-D HAVE_CONFIG_H=1 -D HAVE_CONFIG_H=1
-I include -I include
@ -104,8 +104,9 @@ if test $compiler = gcc; then
" "
${SHELL} ${srcdest}build-aux/build-lib.sh ${SHELL} ${srcdest}build-aux/build-lib.sh
cp crt1.o .. cp crt1.o ..
) fi
fi compiler=gcc ${SHELL} ${srcdest}build-aux/build-source-lib.sh
)
( (
if test $compiler = gcc; then if test $compiler = gcc; then
@ -145,4 +146,5 @@ fi
AR="${srcdest}pre-inst-env mesar" AR="${srcdest}pre-inst-env mesar"
CC="${srcdest}pre-inst-env mescc -m $mes_bits" CC="${srcdest}pre-inst-env mescc -m $mes_bits"
${SHELL} ${srcdest}build-aux/build-lib.sh ${SHELL} ${srcdest}build-aux/build-lib.sh
${SHELL} ${srcdest}build-aux/build-source-lib.sh
) )

View File

@ -200,12 +200,17 @@ if test -z "$bootstrap"; then
TESTS="$TESTS TESTS="$TESTS
lib/tests/dirent/90-readdir.c lib/tests/dirent/90-readdir.c
lib/tests/io/90-stat.c lib/tests/io/90-stat.c
lib/tests/mes/90-abtod.c
lib/tests/mes/90-dtoab.c
lib/tests/posix/90-execlp.c
lib/tests/posix/90-unsetenv.c lib/tests/posix/90-unsetenv.c
lib/tests/signal/90-signal.c lib/tests/signal/90-signal.c
lib/tests/stdio/90-fopen.c lib/tests/stdio/90-fopen.c
lib/tests/stdio/90-fopen-append.c lib/tests/stdio/90-fopen-append.c
lib/tests/stdio/90-fread-fwrite.c lib/tests/stdio/90-fread-fwrite.c
lib/tests/stdio/90-fseek.c lib/tests/stdio/90-fseek.c
lib/tests/stdio/90-sprintf.c
lib/tests/stdio/90-sscanf.c
lib/tests/stdlib/90-strtol.c lib/tests/stdlib/90-strtol.c
lib/tests/string/90-snprintf.c lib/tests/string/90-snprintf.c
lib/tests/string/90-strpbrk.c lib/tests/string/90-strpbrk.c
@ -222,7 +227,7 @@ lib/tests/scaffold/a1-global-no-clobber.c
fi fi
XFAIL_TESTS=" XFAIL_TESTS="
lib/tests/stdio/90-sprintf.c lib/tests/mes/90-abtod.c
lib/tests/stdio/90-sprintf.c lib/tests/stdio/90-sprintf.c
" "
@ -232,6 +237,7 @@ lib/tests/scaffold/17-compare-unsigned-char-le.c
lib/tests/scaffold/17-compare-unsigned-short-le.c lib/tests/scaffold/17-compare-unsigned-short-le.c
lib/tests/scaffold/66-local-char-array.c lib/tests/scaffold/66-local-char-array.c
lib/tests/scaffold/72-typedef-struct-def-local.c lib/tests/scaffold/72-typedef-struct-def-local.c
lib/tests/mes/90-dtoab.c
lib/tests/scaffold/90-goto-var.c lib/tests/scaffold/90-goto-var.c
lib/tests/scaffold/91-goto-array.c lib/tests/scaffold/91-goto-array.c
" "
@ -248,11 +254,6 @@ lib/tests/scaffold/a0-call-trunc-int.c
fi fi
fi fi
if test $mes_cpu = x86; then
XFAIL_TESTS="$XFAIL_TESTS
"
fi
if test $mes_cpu = x86_64; then if test $mes_cpu = x86_64; then
XFAIL_TESTS="$XFAIL_TESTS XFAIL_TESTS="$XFAIL_TESTS
lib/tests/stdio/70-printf-stdarg.c lib/tests/stdio/70-printf-stdarg.c
@ -261,6 +262,8 @@ fi
if test $compiler = gcc; then if test $compiler = gcc; then
XFAIL_TESTS="$XFAIL_TESTS XFAIL_TESTS="$XFAIL_TESTS
lib/tests/mes/90-abtod.c
lib/tests/mes/90-dtoab.c
" "
if test $mes_cpu = x86; then if test $mes_cpu = x86; then
@ -278,6 +281,7 @@ lib/tests/stdio/80-sscanf.c
lib/tests/mes/90-abtod.c lib/tests/mes/90-abtod.c
lib/tests/posix/90-execlp.c lib/tests/posix/90-execlp.c
lib/tests/string/90-snprintf.c lib/tests/string/90-snprintf.c
lib/tests/stdio/90-sscanf.c
" "
fi fi
fi fi

View File

@ -86,6 +86,8 @@ lib/linux/lseek.c
fi fi
else else
libmes_SOURCES="$libmes_SOURCES libmes_SOURCES="$libmes_SOURCES
lib/mes/abtod.c
lib/mes/dtoab.c
" "
fi fi
@ -156,6 +158,8 @@ lib/ctype/islower.c
lib/ctype/isupper.c lib/ctype/isupper.c
lib/ctype/tolower.c lib/ctype/tolower.c
lib/ctype/toupper.c lib/ctype/toupper.c
lib/mes/abtod.c
lib/mes/dtoab.c
lib/mes/search-path.c lib/mes/search-path.c
lib/posix/execvp.c lib/posix/execvp.c
lib/stdio/fclose.c lib/stdio/fclose.c
@ -180,6 +184,7 @@ lib/stdio/vsprintf.c
lib/stdio/vsscanf.c lib/stdio/vsscanf.c
lib/stdlib/calloc.c lib/stdlib/calloc.c
lib/stdlib/qsort.c lib/stdlib/qsort.c
lib/stdlib/strtod.c
lib/stdlib/strtof.c lib/stdlib/strtof.c
lib/stdlib/strtol.c lib/stdlib/strtol.c
lib/stdlib/strtold.c lib/stdlib/strtold.c
@ -199,7 +204,6 @@ lib/stub/ldexp.c
lib/stub/mprotect.c lib/stub/mprotect.c
lib/stub/localtime.c lib/stub/localtime.c
lib/stub/sigemptyset.c lib/stub/sigemptyset.c
lib/stub/strtod.c
lib/$mes_cpu-mes-$compiler/setjmp.c lib/$mes_cpu-mes-$compiler/setjmp.c
" "
@ -217,16 +221,21 @@ lib/ctype/isalnum.c
lib/ctype/isalpha.c lib/ctype/isalpha.c
lib/ctype/isascii.c lib/ctype/isascii.c
lib/ctype/iscntrl.c lib/ctype/iscntrl.c
lib/ctype/isgraph.c
lib/ctype/isprint.c lib/ctype/isprint.c
lib/ctype/ispunct.c lib/ctype/ispunct.c
lib/dirent/__getdirentries.c lib/dirent/__getdirentries.c
lib/dirent/closedir.c lib/dirent/closedir.c
lib/dirent/opendir.c lib/dirent/opendir.c
lib/dirent/readdir.c lib/dirent/readdir.c
lib/math/ceil.c
lib/math/fabs.c lib/math/fabs.c
lib/math/floor.c
lib/math/labs.c
lib/mes/fdgets.c lib/mes/fdgets.c
lib/posix/alarm.c lib/posix/alarm.c
lib/posix/execl.c lib/posix/execl.c
lib/posix/execlp.c
lib/posix/mktemp.c lib/posix/mktemp.c
lib/posix/raise.c lib/posix/raise.c
lib/posix/sbrk.c lib/posix/sbrk.c
@ -237,12 +246,16 @@ lib/stdio/feof.c
lib/stdio/fgets.c lib/stdio/fgets.c
lib/stdio/fileno.c lib/stdio/fileno.c
lib/stdio/freopen.c lib/stdio/freopen.c
lib/stdio/fscanf.c
lib/stdio/perror.c lib/stdio/perror.c
lib/stdio/rewind.c
lib/stdio/vfscanf.c
lib/stdlib/__exit.c lib/stdlib/__exit.c
lib/stdlib/abort.c lib/stdlib/abort.c
lib/stdlib/abs.c lib/stdlib/abs.c
lib/stdlib/alloca.c lib/stdlib/alloca.c
lib/stdlib/atexit.c lib/stdlib/atexit.c
lib/stdlib/atof.c
lib/stdlib/atol.c lib/stdlib/atol.c
lib/stdlib/mbstowcs.c lib/stdlib/mbstowcs.c
lib/string/bcmp.c lib/string/bcmp.c
@ -256,27 +269,43 @@ lib/string/strerror.c
lib/string/strncat.c lib/string/strncat.c
lib/string/strpbrk.c lib/string/strpbrk.c
lib/string/strspn.c lib/string/strspn.c
lib/string/strtok.c
lib/stub/__cleanup.c lib/stub/__cleanup.c
lib/stub/asctime.c
lib/stub/atan2.c
lib/stub/bsearch.c lib/stub/bsearch.c
lib/stub/chown.c lib/stub/chown.c
lib/stub/cos.c
lib/stub/ctime.c lib/stub/ctime.c
lib/stub/exp.c
lib/stub/fpurge.c lib/stub/fpurge.c
lib/stub/freadahead.c lib/stub/freadahead.c
lib/stub/frexp.c lib/stub/frexp.c
lib/stub/getgrgid.c
lib/stub/getgrnam.c
lib/stub/getlogin.c lib/stub/getlogin.c
lib/stub/getpgid.c
lib/stub/getpgrp.c
lib/stub/getpwnam.c lib/stub/getpwnam.c
lib/stub/getpwuid.c lib/stub/getpwuid.c
lib/stub/gmtime.c lib/stub/gmtime.c
lib/stub/log.c
lib/stub/mktime.c
lib/stub/modf.c
lib/stub/pclose.c lib/stub/pclose.c
lib/stub/popen.c lib/stub/popen.c
lib/stub/pow.c
lib/stub/rand.c lib/stub/rand.c
lib/stub/setbuf.c lib/stub/setbuf.c
lib/stub/setgrent.c
lib/stub/setlocale.c lib/stub/setlocale.c
lib/stub/setvbuf.c lib/stub/setvbuf.c
lib/stub/sigaddset.c lib/stub/sigaddset.c
lib/stub/sigblock.c lib/stub/sigblock.c
lib/stub/sigdelset.c lib/stub/sigdelset.c
lib/stub/sigsetmask.c lib/stub/sigsetmask.c
lib/stub/sin.c
lib/stub/sqrt.c
lib/stub/strftime.c lib/stub/strftime.c
lib/stub/sys_siglist.c lib/stub/sys_siglist.c
lib/stub/system.c lib/stub/system.c
@ -303,14 +332,19 @@ lib/linux/kill.c
lib/linux/link.c lib/linux/link.c
lib/linux/lstat.c lib/linux/lstat.c
lib/linux/mkdir.c lib/linux/mkdir.c
lib/linux/mknod.c
lib/linux/mmap.c
lib/linux/munmap.c
lib/linux/nanosleep.c lib/linux/nanosleep.c
lib/linux/pipe.c lib/linux/pipe.c
lib/linux/readlink.c
lib/linux/rename.c lib/linux/rename.c
lib/linux/setgid.c lib/linux/setgid.c
lib/linux/settimer.c lib/linux/settimer.c
lib/linux/setuid.c lib/linux/setuid.c
lib/linux/signal.c lib/linux/signal.c
lib/linux/sigprogmask.c lib/linux/sigprogmask.c
lib/linux/symlink.c
" "
fi fi

View File

@ -77,13 +77,15 @@ else
cp $_v ChangeLog ${DESTDIR}${docdir} cp $_v ChangeLog ${DESTDIR}${docdir}
fi fi
if test -f module/mescc.go; then
__exclude_go=--exclude='*.go'
__exclude_scm=--exclude='*.scm'
fi
mkdir -p $DESTDIR$libdir mkdir -p $DESTDIR$libdir
mkdir -p $DESTDIR$pkgdatadir mkdir -p $DESTDIR$pkgdatadir
# rm -f $(find lib -type f -a -executable)
# rm -f $(find scaffold -type f -a -executable)
tar -cf- -C ${srcdir} include lib/$mes_cpu-mes | tar -${v}xf- -C $DESTDIR$prefix tar -cf- -C ${srcdir} include lib/$mes_cpu-mes | tar -${v}xf- -C $DESTDIR$prefix
if test -z "$srcdest"; then if test -z "$srcdest"; then
tar -cf- --exclude='*.go' module | tar -${v}xf- -C $DESTDIR$pkgdatadir tar -cf- $__exclude_go module | tar -${v}xf- -C $DESTDIR$pkgdatadir
else else
tar -cf- -C ${srcdest} module | tar -${v}xf- -C $DESTDIR$pkgdatadir tar -cf- -C ${srcdest} module | tar -${v}xf- -C $DESTDIR$pkgdatadir
fi fi
@ -97,8 +99,8 @@ fi
mkdir -p ${DESTDIR}${guile_site_dir} mkdir -p ${DESTDIR}${guile_site_dir}
mkdir -p ${DESTDIR}${guile_site_ccache_dir} mkdir -p ${DESTDIR}${guile_site_ccache_dir}
tar -cf- -C ${srcdest}module --exclude='*.go' . | tar -${v}xf- -C ${DESTDIR}${guile_site_dir} tar -cf- -C ${srcdest}module $__exclude_go . | tar -${v}xf- -C ${DESTDIR}${guile_site_dir}
tar -cf- -C module --exclude='*.scm' . | tar -${v}xf- -C ${DESTDIR}${guile_site_ccache_dir} tar -cf- -C module $__exclude_scm . | tar -${v}xf- -C ${DESTDIR}${guile_site_ccache_dir}
if test -f doc/mes.info; then if test -f doc/mes.info; then
mkdir -p ${DESTDIR}${infodir} mkdir -p ${DESTDIR}${infodir}

View File

@ -25,8 +25,8 @@ srcdir=${srcdir-$(dirname $0)}
. ${srcdest}build-aux/trace.sh . ${srcdest}build-aux/trace.sh
# parse --with-system-libc # parse --with-system-libc
cmdline=$(echo " $@") cmdline=$(echo "$@")
p=${cmdline/ --with-system-libc/} p=$(echo $cmdline | sed s,--with-system-libc,,)
if test "$p" != "$cmdline"; then if test "$p" != "$cmdline"; then
mes_libc=${mes_libc-system} mes_libc=${mes_libc-system}
else else
@ -35,7 +35,7 @@ fi
# parse --with-courage # parse --with-courage
cmdline=$(echo " $@") cmdline=$(echo " $@")
p=${cmdline/ --with-courage/} p=$(echo $cmdline | sed s,--with-courage,,)
if test "$p" != "$cmdline"; then if test "$p" != "$cmdline"; then
courageous=true courageous=true
else else
@ -43,44 +43,40 @@ else
fi fi
# parse --prefix=PREFIX # parse --prefix=PREFIX
p=${cmdline/ --prefix=/ -prefix=} p=$(echo $cmdline | sed s,.*--prefix=,-prefix=,)
if test "$p" != "$cmdline"; then if test "$p" != "$cmdline"; then
p=${p##* -prefix=} p=$(echo $p | sed s,.*-prefix=,,)
p=${p% *} p=$(echo $p | sed 's, .*,,')
p=${p% -*}
prefix=${p-/usr/local} prefix=${p-/usr/local}
else else
prefix=${prefix-/usr/local} prefix=${prefix-/usr/local}
fi fi
# parse --build=BUILD # parse --build=BUILD
p=${cmdline/ --build=/ -build=} p=$(echo $cmdline | sed s,.*--build=,-build=,)
if [ "$p" != "$cmdline" ]; then if [ "$p" != "$cmdline" ]; then
p=${p##* -build=} p=$(echo $p | sed s,.*-build=,,)
p=${p% *} p=$(echo $p | sed 's, .*,,')
p=${p% -*}
build=${p-$build} build=${p-$build}
else else
build=$build build=$build
fi fi
# parse --host=HOST # parse --host=HOST
p=${cmdline/ --host=/ -host=} p=$(echo $cmdline | sed s,.*--host=,-host=,)
if [ "$p" != "$cmdline" ]; then if [ "$p" != "$cmdline" ]; then
p=${p##* -host=} p=$(echo $p | sed s,.*-host=,,)
p=${p% *} p=$(echo $p | sed 's, .*,,')
p=${p% -*}
host=${p-$build} host=${p-$build}
elif test -n "$build"; then elif test -n "$build"; then
host=${host-$build} host=${host-$build}
fi fi
# parse --program-prefix= # parse --program-prefix=
p=${cmdline/ --program-prefix=/ -program-prefix=} p=$(echo $cmdline | sed s,.*--program-prefix=,-program-prefix=,)
if test "$p" != "$cmdline"; then if test "$p" != "$cmdline"; then
p=${p##* -program-prefix=} p=$(echo $p | sed s,.*-program-prefix=,,)
p=${p% *} p=$(echo $p | sed 's, .*,,')
p=${p% -*}
program_prefix=$p program_prefix=$p
fi fi

View File

@ -7,7 +7,9 @@ We are pleased to announce the release of GNU Mes 0.20, representing
147 commits over 38 weeks. 147 commits over 38 weeks.
Mes has now brought the Reduced Binary Seed bootstrap to Guix (bootstrap Mes has now brought the Reduced Binary Seed bootstrap to Guix (bootstrap
a GNU/Linux system without binary GNU toolchain or equivalent). a GNU/Linux system without binary GNU toolchain or equivalent). It
should land in Guix master any day now: a big thank you to everyone who
helped, notably Ludovic and Mark.
This release is a step towards the upcoming Scheme-only bootstrap and This release is a step towards the upcoming Scheme-only bootstrap and
bringing Mes into NixOS and Debian. This effort is now sponsored by bringing Mes into NixOS and Debian. This effort is now sponsored by
@ -67,8 +69,8 @@ Packages are available in Guix master.
Here are the MD5 and SHA1 checksums: Here are the MD5 and SHA1 checksums:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx mes-0.20.tar.gz df839a83e4a2ad6c2a4accc5bf17b1a7 mes-0.20.tar.gz
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx mes-0.20.tar.gz 38d4cb3fa28fa1f5fc57fea9e046d4d8052bbb8c mes-0.20.tar.gz
[*] Use a .sig file to verify that the corresponding file (without the [*] Use a .sig file to verify that the corresponding file (without the
.sig suffix) is intact. First, be sure to download both the .sig file .sig suffix) is intact. First, be sure to download both the .sig file
@ -83,6 +85,11 @@ Packages are available in Guix master.
and rerun the 'gpg --verify' command. and rerun the 'gpg --verify' command.
* Get informed, get involved
See https://bootstrappable.org
Join #bootstrappable on irc.freenode.net.
* Changes in 0.20 since 0.19 * Changes in 0.20 since 0.19
** Core ** Core
*** The build system has been simplified, again. *** The build system has been simplified, again.
@ -108,6 +115,9 @@ Packages are available in Guix master.
*** string->number now support #x hex-prefix. *** string->number now support #x hex-prefix.
*** ungetc now has a buffer per file handle. *** ungetc now has a buffer per file handle.
Greetings,
janneke and Danny.
[0] https://www.gnu.org/software/mes [0] https://www.gnu.org/software/mes
[1] http://joyofsource.com/reduced-binary-seed-bootstrap.html [1] http://joyofsource.com/reduced-binary-seed-bootstrap.html
[2] https://www.gnu.org/software/guix [2] https://www.gnu.org/software/guix

View File

@ -131,7 +131,7 @@ extensive examples, including parsers for the Javascript and C99 languages.")
(uri (string-append (uri (string-append
"https://ftp.gnu.org/pub/gnu/mes/mes-" version ".tar.gz")) "https://ftp.gnu.org/pub/gnu/mes/mes-" version ".tar.gz"))
(sha256 (sha256
(base32 #!mes!# "06qkwkahcpzk5v4qydpvcvzm7lx8g8pflc48f9l7bpjz6hl5lk4s")))) (base32 #!mes!# "04pajp8v31na34ls4730ig5f6miiplhdvkmsb9ls1b8bbmw2vb4n"))))
(build-system gnu-build-system) (build-system gnu-build-system)
(supported-systems '("i686-linux" "x86_64-linux")) (supported-systems '("i686-linux" "x86_64-linux"))
(propagated-inputs (propagated-inputs

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -35,6 +35,7 @@ int isalpha (int c);
int isascii (int c); int isascii (int c);
int iscntrl (int c); int iscntrl (int c);
int isdigit (int c); int isdigit (int c);
int isgraph (int c);
int islower (int c); int islower (int c);
int isnumber (int c, int base); int isnumber (int c, int base);
int isprint (int c); int isprint (int c);

View File

@ -38,14 +38,16 @@ int errno;
#define ENOENT 2 #define ENOENT 2
#define EINTR 4 #define EINTR 4
#define EIO 5 #define EIO 5
#define ENXIO 6
#define E2BIG 7 #define E2BIG 7
#define ENOEXEC 8 #define ENOEXEC 8
#define EBADF 9 #define EBADF 9
#define ECHILD 10 #define ECHILD 10
#define EAGAIN 11 #define EAGAIN 11
#define ENOMEM 12 #define ENOMEM 12
#define EACCES 13 #define EACCES 13
#define EEXIST 17 #define EEXIST 17
#define EXDEV 18
#define ENOTDIR 20 #define ENOTDIR 20
#define EISDIR 21 #define EISDIR 21
#define EINVAL 22 #define EINVAL 22

View File

@ -48,6 +48,7 @@
#define F_GETFL 3 #define F_GETFL 3
#define F_SETFL 4 #define F_SETFL 4
#define creat(file_name, mode) open (file_name, O_WRONLY | O_CREAT | O_TRUNC, mode)
int dup (int old); int dup (int old);
int dup2 (int old, int new); int dup2 (int old, int new);
int fcntl (int filedes, int command, ...); int fcntl (int filedes, int command, ...);

View File

@ -29,6 +29,19 @@
#define DBL_MIN_EXP -1021 #define DBL_MIN_EXP -1021
#define LDBL_MIN_EXP -1021 #define LDBL_MIN_EXP -1021
// gcc-4.6
#define DBL_EPSILON 1
#define DBL_MANT_DIG 1
#define DBL_MAX INT_MAX
#define DBL_MIN INT_MIN
#define FLT_RADIX 10
#define LDBL_EPSILON 1
#define LDBL_MANT_DIG 1
#define LDBL_MAX INT_MAX
#define LDBL_MIN INT_MIN
#endif // ! SYSTEM_LIBC #endif // ! SYSTEM_LIBC
#endif // __MES_FLOAT_H #endif // __MES_FLOAT_H

View File

@ -83,4 +83,13 @@
// make+POSIX // make+POSIX
#define SYS_sigprocmask 0x7e #define SYS_sigprocmask 0x7e
// tar
#define SYS_symlink 0x53
#define SYS_readlink 0x55
#define SYS_mknod 0x0e
// gcc-4.6.4
#define SYS_mmap 0x5a
#define SYS_munmap 0x5b
#endif // __MES_LINUX_X86_SYSCALL_H #endif // __MES_LINUX_X86_SYSCALL_H

View File

@ -80,4 +80,13 @@
// make+SYSTEM_LIBC // make+SYSTEM_LIBC
#define SYS_rt_sigprocmask 0x0e #define SYS_rt_sigprocmask 0x0e
// tar
#define SYS_symlink 0x58
#define SYS_readlink 0x59
#define SYS_mknod 0x85
// gcc-4.6.4
#define SYS_mmap 0x09
#define SYS_munmap 0x0b
#endif // __MES_LINUX_X86_64_SYSCALL_H #endif // __MES_LINUX_X86_64_SYSCALL_H

View File

@ -24,8 +24,21 @@
#undef __MES_MATH_H #undef __MES_MATH_H
#include_next <math.h> #include_next <math.h>
#else // ! SYSTEM_LIBC #else // ! SYSTEM_LIBC
double atan2 (double y, double x);
double ceil (double x);
double cos (double x);
double exp (double x);
double fabs (double number); double fabs (double number);
double floor (double x);
long int labs (long int number);
double ldexp (double value, int exponent); double ldexp (double value, int exponent);
double log (double x);
double modf (double value, double *integer_part);
double pow (double base, double power);
double sin (double x);
double sqrt (double x);
#endif // ! SYSTEM_LIBC #endif // ! SYSTEM_LIBC
#endif // __MES_MATH_H #endif // __MES_MATH_H

View File

@ -28,7 +28,9 @@ void __ungetc_init ();
void __ungetc_clear (int filedes); void __ungetc_clear (int filedes);
void __ungetc_set (int filedes, int c); void __ungetc_set (int filedes, int c);
int __ungetc_p (int filedes); int __ungetc_p (int filedes);
double abtod (char const **p, int base);
long abtol (char const **p, int base); long abtol (char const **p, int base);
char *dtoab (double number, int base, int signed_p);
char *itoa (int number); char *itoa (int number);
char *ltoa (long number); char *ltoa (long number);
char *ltoab (long x, int base); char *ltoab (long x, int base);

View File

@ -34,11 +34,14 @@
typedef char *va_list; typedef char *va_list;
#define va_start(ap, last) (void)((ap) = (char*)(&(last) + 1)) #define va_start(ap, last) (void)((ap) = (char*)(&(last) + 1))
#define va_arg(ap, type) (type)(((long*)((ap) = ((ap) + sizeof (void*))))[-1]) #define va_arg(ap, type) (type)(((long*)((ap) = ((ap) + sizeof (void*))))[-1])
#define va_align(ap, alignment) ((char*)((((unsigned long) (ap)) + (alignment) - 1) &~ ((alignment) - 1)))
#define va_arg8(ap, type) (type)(((double*)((ap) = (va_align((ap), 8) + sizeof(double))))[-1])
#define va_end(ap) (void)((ap) = 0) #define va_end(ap) (void)((ap) = 0)
#define va_copy(dest, src) dest = src #define va_copy(dest, src) dest = src
int vexec (char const *file_name, va_list ap); int vexec (char const *file_name, va_list ap);
int vfprintf (FILE * stream, char const *template, va_list ap); int vfprintf (FILE * stream, char const *template, va_list ap);
int vfscanf (FILE * stream, char const *template, va_list ap);
int vprintf (char const *format, va_list ap); int vprintf (char const *format, va_list ap);
int vsprintf (char *str, char const *format, va_list ap); int vsprintf (char *str, char const *format, va_list ap);
int vsnprintf (char *str, size_t size, char const *format, va_list ap); int vsnprintf (char *str, size_t size, char const *format, va_list ap);

View File

@ -85,6 +85,12 @@ typedef unsigned uintmax_t;
#define INT_MIN -2147483648 #define INT_MIN -2147483648
#define INT_MAX 2147483647 #define INT_MAX 2147483647
#define SHRT_MAX INT16_MAX
#define SHRT_MIN INT16_MIN
#define USHRT_MAX UINT16_MAX
#define USHRT_MIN UINT16_MIN
#if __i386__ #if __i386__
#define LONG_MIN INT_MIN #define LONG_MIN INT_MIN
#define LONG_MAX INT_MAX #define LONG_MAX INT_MAX
@ -103,6 +109,8 @@ typedef unsigned uintmax_t;
#define SIZE_MAX UINT64_MAX #define SIZE_MAX UINT64_MAX
#endif #endif
#define SSIZE_MAX LONG_MAX
#endif // ! SYSTEM_LIBC #endif // ! SYSTEM_LIBC
#endif // __MES_STDINT_H #endif // __MES_STDINT_H

View File

@ -69,6 +69,7 @@ int fprintf (FILE * stream, char const *format, ...);
int fpurge (FILE * stream); int fpurge (FILE * stream);
int fputc (int c, FILE * stream); int fputc (int c, FILE * stream);
int fputs (char const *s, FILE * stream); int fputs (char const *s, FILE * stream);
int fscanf (FILE * stream, char const *template, ...);
int fseek (FILE * stream, long offset, int whence); int fseek (FILE * stream, long offset, int whence);
int getc (FILE * stream); int getc (FILE * stream);
int getchar (void); int getchar (void);
@ -78,10 +79,11 @@ int putc (int c, FILE * stream);
int putchar (int c); int putchar (int c);
int puts (char const *s); int puts (char const *s);
int remove (char const *file_name); int remove (char const *file_name);
void rewind (FILE * stream);
int setvbuf (FILE * stream, char *buf, int mode, size_t size); int setvbuf (FILE * stream, char *buf, int mode, size_t size);
int snprintf (char *str, size_t size, char const *format, ...); int snprintf (char *str, size_t size, char const *format, ...);
int sprintf (char *str, char const *format, ...); int sprintf (char *str, char const *format, ...);
int sscanf (char const *str, const char *format, ...); int sscanf (char const *str, char const *format, ...);
int ungetc (int c, FILE * stream); int ungetc (int c, FILE * stream);
long ftell (FILE * stream); long ftell (FILE * stream);
size_t fread (void *ptr, size_t size, size_t count, FILE * stream); size_t fread (void *ptr, size_t size, size_t count, FILE * stream);

View File

@ -36,6 +36,7 @@ typedef int (*comparison_fn_t) (void const *, void const *);
#include <sys/types.h> #include <sys/types.h>
#include <alloca.h> #include <alloca.h>
void abort (void);
double atof (char const *s); double atof (char const *s);
int atoi (char const *s); int atoi (char const *s);
int atexit (void (*function) (void)); int atexit (void (*function) (void));

View File

@ -48,6 +48,7 @@ char *strncpy (char *to, char const *from, size_t size);
int strncmp (char const *, char const *, size_t); int strncmp (char const *, char const *, size_t);
char *strrchr (char const *s, int c); char *strrchr (char const *s, int c);
char *strstr (char const *haystack, char const *needle); char *strstr (char const *haystack, char const *needle);
char *strtok (char *new_string, char const *delimiters);
char *strlwr (char *string); char *strlwr (char *string);
char *strupr (char *string); char *strupr (char *string);

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -25,19 +25,25 @@
#include_next <sys/mman.h> #include_next <sys/mman.h>
#else // ! SYSTEM_LIBC #else // ! SYSTEM_LIBC
#ifndef __MES_SIZE_T #include <sys/types.h>
#define __MES_SIZE_T
typedef unsigned long size_t; #define MAP_SHARED 0x01
#endif #define MAP_PRIVATE 0x02
#define MAP_ANONYMOUS 0x20
#define MAP_POPULATE 0x08000
#define MAP_ANON MAP_ANONYMOUS
#define MAP_FAILED ((void*)-1)
#define PROT_NONE 0 #define PROT_NONE 0
#define PROT_READ 1 #define PROT_READ 1
#define PROT_WRITE 2 #define PROT_WRITE 2
#define PROT_EXEC 4 #define PROT_EXEC 4
void *mmap (void *address, size_t length, int protect, int flags, int filedes, off_t offset);
int mprotect (void *addr, size_t len, int prot); int mprotect (void *addr, size_t len, int prot);
int munmap (void *addr, size_t length);
#endif // ! SYSTEM_LIBC #endif // ! SYSTEM_LIBC
#endif // __MES_SYS_MMAN_H #endif // __MES_SYS_MMAN_H

View File

@ -85,10 +85,12 @@ struct stat
int chmod (char const *file_name, mode_t mode); int chmod (char const *file_name, mode_t mode);
int fstat (int filedes, struct stat *buf); int fstat (int filedes, struct stat *buf);
int mkdir (char const *file_name, mode_t mode); int mkdir (char const *file_name, mode_t mode);
int mknod (char const *file_name, mode_t mode, dev_t dev);
int chown (char const *file_name, uid_t owner, gid_t group); int chown (char const *file_name, uid_t owner, gid_t group);
int rmdir (char const *file_name); int rmdir (char const *file_name);
int stat (char const *file_name, struct stat *buf); int stat (char const *file_name, struct stat *buf);
#define S_IFIFO 0010000
#define S_IFCHR 0020000 #define S_IFCHR 0020000
#define S_IFDIR 0040000 #define S_IFDIR 0040000
#define S_IFBLK 0060000 #define S_IFBLK 0060000
@ -96,6 +98,7 @@ int stat (char const *file_name, struct stat *buf);
#define S_IFLNK 0120000 #define S_IFLNK 0120000
#define S_IFMT 0170000 #define S_IFMT 0170000
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)

View File

@ -138,6 +138,15 @@ typedef long ssize_t;
typedef unsigned uid_t; typedef unsigned uid_t;
#endif #endif
#ifndef __WCHAR_T
#define __WCHAR_T
#ifndef __MES_WCHAR_T
#define __MES_WCHAR_T
#undef wchar_t
typedef int wchar_t;
#endif
#endif
#endif // ! SYSTEM_LIBC #endif // ! SYSTEM_LIBC
#endif // __MES_SYS_TYPES_H #endif // __MES_SYS_TYPES_H

View File

@ -49,6 +49,14 @@
#define CS8 0000060 #define CS8 0000060
#define PARENB 0000400 #define PARENB 0000400
struct winsize
{
unsigned short ws_row;
unsigned short ws_col;
unsigned short ws_xpixel;
unsigned short ws_ypixel;
};
struct termio struct termio
{ {
unsigned short c_iflag; unsigned short c_iflag;

View File

@ -56,9 +56,11 @@ struct timespec
#endif // __MES_STRUCT_TIMESPEC #endif // __MES_STRUCT_TIMESPEC
#define CLOCK_PROCESS_CPUTIME_ID 2 #define CLOCK_PROCESS_CPUTIME_ID 2
char *asctime (struct tm const *broken_time);
int clock_gettime (clockid_t clk_id, struct timespec *tp); int clock_gettime (clockid_t clk_id, struct timespec *tp);
struct tm *localtime (time_t const *timep); struct tm *localtime (time_t const *timep);
struct tm *gmtime (time_t const *time); struct tm *gmtime (time_t const *time);
time_t mktime (struct tm *broken_time);
int nanosleep (struct timespec const *requested_time, struct timespec const *remaining); int nanosleep (struct timespec const *requested_time, struct timespec const *remaining);
time_t time (time_t * tloc); time_t time (time_t * tloc);

View File

@ -62,6 +62,7 @@ unsigned int alarm (unsigned int seconds);
int close (int fd); int close (int fd);
int execv (char const *file_name, char *const argv[]); int execv (char const *file_name, char *const argv[]);
int execl (char const *file_name, char const *arg, ...); int execl (char const *file_name, char const *arg, ...);
int execlp (char const *file_name, char const *arg, ...);
int execve (char const *file, char *const argv[], char *const env[]); int execve (char const *file, char *const argv[], char *const env[]);
int execvp (char const *file, char *const argv[]); int execvp (char const *file, char *const argv[]);
int fork (void); int fork (void);
@ -73,21 +74,24 @@ int setgid (gid_t newgid);
int setuid (uid_t newuid); int setuid (uid_t newuid);
uid_t geteuid (void); uid_t geteuid (void);
gid_t getegid (void); gid_t getegid (void);
pid_t getpgrp (void);
pid_t getpid (void); pid_t getpid (void);
pid_t getppid (void); pid_t getppid (void);
int getpgid (pid_t pid);
int isatty (int fd); int isatty (int fd);
int link (char const *oldname, char const *newname); int link (char const *old_name, char const *new_name);
off_t lseek (int fd, off_t offset, int whence); off_t lseek (int fd, off_t offset, int whence);
ssize_t read (int fd, void *buffer, size_t size); ssize_t read (int fd, void *buffer, size_t size);
ssize_t readlink (char const *file_name, char *buffer, size_t size);
#if __SBRK_CHAR_PTRDIFF #if __SBRK_CHAR_PTRDIFF
/* xmalloc in binutils <= 2.10.1 uses this old prototype */ /* xmalloc in binutils <= 2.10.1 uses this old prototype */
char *sbrk (ptrdiff_t delta); char *sbrk (ptrdiff_t delta);
#else #else
void *sbrk (intptr_t delta); void *sbrk (intptr_t delta);
#endif #endif
int symlink (char const *old_name, char const *new_name);
int unlink (char const *file_name); int unlink (char const *file_name);
ssize_t write (int filedes, void const *buffer, size_t size); ssize_t write (int filedes, void const *buffer, size_t size);
pid_t getpid (void);
#endif // ! SYSTEM_LIBC #endif // ! SYSTEM_LIBC

27
lib/ctype/isgraph.c Normal file
View File

@ -0,0 +1,27 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <ctype.h>
int
isgraph (int c)
{
return c > 32 && c < 127;
}

29
lib/linux/mknod.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019 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 <linux/syscall.h>
#include <syscall.h>
#include <sys/stat.h>
int
mknod (char const *file_name, mode_t mode, dev_t dev)
{
return _sys_call3 (SYS_mknod, (long) file_name, (long) mode, (long) dev);
}

29
lib/linux/mmap.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019 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 <linux/syscall.h>
#include <syscall.h>
#include <sys/mman.h>
void *
mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
{
return (void *)_sys_call6 (SYS_mmap, (long) addr, (long) len, (int) prot, (int) flags, (int) fd, (long) offset);
}

29
lib/linux/munmap.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019 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 <linux/syscall.h>
#include <syscall.h>
#include <sys/mman.h>
int
munmap (void *addr, size_t length)
{
return _sys_call2 (SYS_munmap, (long) addr, (long) length);
}

29
lib/linux/readlink.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019 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 <linux/syscall.h>
#include <syscall.h>
#include <sys/stat.h>
ssize_t
readlink (char const *file_name, char *buffer, size_t size)
{
return _sys_call3 (SYS_readlink, (long) file_name, (long) buffer, (long) size);
}

29
lib/linux/symlink.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019 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 <linux/syscall.h>
#include <syscall.h>
#include <unistd.h>
int
symlink (char const *old_name, char const *new_name)
{
return _sys_call2 (SYS_symlink, (long) old_name, (long) new_name);
}

View File

@ -141,3 +141,20 @@ _sys_call4 (long sys_call, long one, long two, long three, long four)
errno = 0; errno = 0;
return r; return r;
} }
long
_sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six)
{
long r;
asm (
"mov %1,%%eax\n\t"
"mov %%ebp,%%ebx\n\t"
"add $0x0c,%%ebx\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
: "rm" (sys_call)
: "eax", "ebx"
);
return r;
}

View File

@ -66,6 +66,15 @@ __sys_call4 (int sys_call, int one, int two, int three, int four)
asm ("int____$0x80"); asm ("int____$0x80");
} }
int
__sys_call6 (int sys_call, int one, int two, int three, int four, int five, int six)
{
asm ("mov____0x8(%ebp),%eax !0x08");
asm ("mov____%ebp,%ebx");
asm ("add____$i8,%ebx !0x0c");
asm ("int____$0x80");
}
int int
_sys_call (int sys_call) _sys_call (int sys_call)
{ {
@ -135,3 +144,9 @@ _sys_call4 (int sys_call, int one, int two, int three, int four)
errno = 0; errno = 0;
return r; return r;
} }
int
_sys_call6 (int sys_call, int one, int two, int three, int four, int five, int six)
{
return __sys_call6 (sys_call, one, two, three, four, five, six);
}

View File

@ -150,3 +150,26 @@ _sys_call4 (long sys_call, long one, long two, long three, long four)
errno = 0; errno = 0;
return r; return r;
} }
long
_sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six)
{
long r;
asm (
"mov %2,%%rdi\n\t"
"mov %3,%%rsi\n\t"
"mov %4,%%rdx\n\t"
"mov %5,%%r10\n\t"
"mov %6,%%r8\n\t"
"mov %7,%%r9\n\t"
"mov %1,%%rax\n\t"
// );
// asm (
"syscall \n\t"
"mov %%rax,%0\n\t"
: "=r" (r)
: "rm" (sys_call), "rm" (one), "rm" (two), "rm" (three), "rm" (four), "rm" (five), "rm" (six)
: "rax", "rdi", "rsi", "rdx", "r10", "r8", "r9"
);
return r;
}

View File

@ -23,7 +23,7 @@
long long
//__sys_call (long one, long two, long three, long four) //__sys_call (long one, long two, long three, long four)
__sys_call (long sys_call, long one, long two, long three, long four) __sys_call (long sys_call, long one, long two, long three, long four, long five, long six)
{ {
#if 1 // !MES_CCAMD64 #if 1 // !MES_CCAMD64
// asm ("mov____0x8(%rbp),%rdi !0x10"); // asm ("mov____0x8(%rbp),%rdi !0x10");
@ -37,6 +37,8 @@ __sys_call (long sys_call, long one, long two, long three, long four)
asm ("mov____0x8(%rbp),%rsi !0x20"); asm ("mov____0x8(%rbp),%rsi !0x20");
asm ("mov____0x8(%rbp),%rdx !0x28"); asm ("mov____0x8(%rbp),%rdx !0x28");
asm ("mov____0x8(%rbp),%r10 !0x30"); asm ("mov____0x8(%rbp),%r10 !0x30");
asm ("mov____0x8(%rbp),%r8 !0x38");
asm ("mov____0x8(%rbp),%r9 !0x40");
#endif #endif
asm ("syscall"); asm ("syscall");
@ -121,3 +123,12 @@ _sys_call4 (long sys_call, long one, long two, long three, long four)
errno = 0; errno = 0;
return r; return r;
} }
long
_sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six)
{
// long rax = sys_call;
// long r = __sys_call6 (one, two, three, four, five, six);
long r = __sys_call (sys_call, one, two, three, four, five, six);
return r;
}

29
lib/math/ceil.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <math.h>
double
ceil (double number)
{
long i = number + 0.9999;
number = i;
return number;
}

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -18,7 +18,7 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
//#include <math.h> #include <math.h>
double double
fabs (double number) fabs (double number)

29
lib/math/floor.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <math.h>
double
floor (double number)
{
long i = number;
number = i;
return number;
}

29
lib/math/labs.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <math.h>
long int
labs (long int number)
{
if (number < 0)
return -number;
return number;
}

53
lib/mes/abtod.c Normal file
View File

@ -0,0 +1,53 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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>
double
abtod (char const **p, int base)
{
char const *s = *p;
double d = 0;
int sign_p = 0;
if (!base)
base = 10;
double dbase = base;
long i = abtol (&s, base);
long f = 0;
long e = 0;
if (*s == '.')
{
s++;
f = abtol (&s, base);
}
if (*s == 'e')
{
s++;
e = abtol (&s, base);
}
d = i + f / dbase;
if (e < 0)
while (e++)
d = d / dbase;
while (e--)
d = d * dbase;
*p = s;
return sign_p ? -d : d;
}

View File

@ -26,12 +26,16 @@ abtol (char const **p, int base)
{ {
char const *s = *p; char const *s = *p;
int i = 0; int i = 0;
int sign = 1; int sign_p = 0;
if (!base) if (!base)
base = 10; base = 10;
while (isspace (*s))
s++;
if (*s && *s == '+')
s++;
if (*s && *s == '-') if (*s && *s == '-')
{ {
sign = -1; sign_p = 1;
s++; s++;
} }
while (isnumber (*s, base)) while (isnumber (*s, base))
@ -42,5 +46,5 @@ abtol (char const **p, int base)
s++; s++;
} }
*p = s; *p = s;
return i * sign; return sign_p ? -i : i;
} }

46
lib/mes/dtoab.c Normal file
View File

@ -0,0 +1,46 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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 <limits.h>
#include <string.h>
char *
dtoab (double d, int base, int signed_p)
{
static char dtoa_buf[40];
long i = (long) d;
char *p = ntoab (i, base, signed_p);
strcpy (dtoa_buf, p);
long f = (d - (double) i) * (double) 100000000;
if (f)
{
if (f < 0)
f = -f;
strcat (dtoa_buf, ".");
p = ntoab (f, base, 1);
strcat (dtoa_buf, p);
p = strchr (dtoa_buf, 0);
p--;
while (*p && *p == '0')
*p-- = 0;
}
return dtoa_buf;
}

View File

@ -23,22 +23,13 @@
#include <unistd.h> #include <unistd.h>
int int
execl (char const *file_name, char const *arg, ...) vexec (char const *file_name, va_list ap)
{ {
if (__mes_debug () > 2) char *arg = va_arg (ap, char *);
{
eputs ("execl ");
eputs (file_name);
eputs ("\n");
}
char *argv[1000]; // POSIX minimum 4096 char *argv[1000]; // POSIX minimum 4096
int i = 0; int i = 0;
va_list ap; argv[i++] = (char *) file_name;
va_start (ap, arg);
argv[i++] = (char *)file_name;
arg = va_arg (ap, char const *);
while (arg) while (arg)
{ {
argv[i++] = arg; argv[i++] = arg;
@ -57,3 +48,20 @@ execl (char const *file_name, char const *arg, ...)
va_end (ap); va_end (ap);
return r; return r;
} }
int
execl (char const *file_name, char const *arg, ...)
{
va_list ap;
int r;
va_start (ap, arg);
if (__mes_debug () > 2)
{
eputs ("execl ");
eputs (file_name);
eputs ("\n");
}
r = vexec (file_name, ap);
va_end (ap);
return r;
}

47
lib/posix/execlp.c Normal file
View File

@ -0,0 +1,47 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 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 <errno.h>
#include <stdarg.h>
int
execlp (char const *file_name, char const *arg, ...)
{
va_list ap;
int r;
va_start (ap, arg);
if (file_name[0] != '/')
file_name = search_path (file_name);
if (__mes_debug () > 2)
{
eputs ("execlp ");
eputs (file_name ? file_name : "0");
eputs ("\n");
}
if (!file_name)
{
errno = ENOENT;
return -1;
}
r = vexec (file_name, ap);
va_end (ap);
return r;
}

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -25,5 +25,8 @@
int int
fflush (FILE * stream) fflush (FILE * stream)
{ {
fsync ((long) stream); int filedes = (long) stream;
if (filedes < 3)
return 0;
return fsync (filedes);
} }

33
lib/stdio/fscanf.c Normal file
View File

@ -0,0 +1,33 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018,2019 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 <stdarg.h>
#include <stdio.h>
int
fscanf (FILE * stream, char const *template, ...)
{
va_list ap;
va_start (ap, template);
int r = vfscanf (stream, template, ap);
va_end (ap);
return r;
}

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -18,16 +18,10 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <mes/lib.h> #include <stdio.h>
#include <errno.h>
int void
rewind (int x) rewind (FILE * stream)
{ {
static int stub = 0; fseek (stream, 0, SEEK_SET);
if (__mes_debug () && !stub)
eputs ("rewind stub\n");
stub = 1;
errno = 0;
return 0;
} }

View File

@ -23,7 +23,7 @@
#include <stdio.h> #include <stdio.h>
int int
sscanf (char const *str, const char *template, ...) sscanf (char const *str, char const *template, ...)
{ {
va_list ap; va_list ap;
va_start (ap, template); va_start (ap, template);

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -33,7 +33,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
if (*p != '%') if (*p != '%')
{ {
count++; count++;
fputc (*p++, fd); fputc (*p++, f);
} }
else else
{ {
@ -41,6 +41,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
char c = *p; char c = *p;
int left_p = 0; int left_p = 0;
int precision = -1; int precision = -1;
int prefix_p = 0;
int width = -1; int width = -1;
if (c == '-') if (c == '-')
{ {
@ -48,10 +49,20 @@ vfprintf (FILE * f, char const *format, va_list ap)
c = *++p; c = *++p;
} }
char pad = ' '; char pad = ' ';
if (c == ' ')
{
pad = c;
c = *++p;
}
if (c == '#')
{
prefix_p = 1;
c = *++p;
}
if (c == '0') if (c == '0')
{ {
pad = c; pad = c;
c = *p++; c = *++p;
} }
if (c >= '0' && c <= '9') if (c >= '0' && c <= '9')
{ {
@ -88,7 +99,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
{ {
case '%': case '%':
{ {
fputc (*p, fd); fputc (*p, f);
count++; count++;
break; break;
} }
@ -96,7 +107,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
{ {
char _c; char _c;
_c = va_arg (ap, long); _c = va_arg (ap, long);
fputc (_c, fd); fputc (_c, f);
break; break;
} }
case 'd': case 'd':
@ -108,7 +119,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
{ {
long d = va_arg (ap, long); long d = va_arg (ap, long);
int base = c == 'o' ? 8 : c == 'x' || c == 'X' ? 16 : 10; int base = c == 'o' ? 8 : c == 'x' || c == 'X' ? 16 : 10;
char const *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X'); char *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X');
if (c == 'X') if (c == 'X')
strupr (s); strupr (s);
int length = strlen (s); int length = strlen (s);
@ -129,6 +140,18 @@ vfprintf (FILE * f, char const *format, va_list ap)
count++; count++;
} }
} }
if (prefix_p && *s && c == 'o')
{
fputc ('0', f);
width--;
}
if (prefix_p && *s && (c == 'x' || c == 'X'))
{
fputc ('0', f);
width--;
fputc ('x', f);
width--;
}
while (*s) while (*s)
{ {
if (precision-- <= 0) if (precision-- <= 0)
@ -182,6 +205,50 @@ vfprintf (FILE * f, char const *format, va_list ap)
} }
break; break;
} }
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
{
double d = va_arg8 (ap, double);
char *s = dtoab (d, 10, 1);
if (c == 'E' || c == 'G')
strupr (s);
int length = strlen (s);
if (precision == -1)
precision = length;
if (!left_p)
{
while (width-- > precision)
{
fputc (pad, f);
count++;
}
while (precision > length)
{
fputc (' ', f);
precision--;
width--;
count++;
}
}
while (*s)
{
if (precision-- <= 0)
break;
width--;
fputc (*s++, f);
count++;
}
while (width > 0)
{
width--;
fputc (pad, f);
count++;
}
break;
}
case 'n': case 'n':
{ {
int *n = va_arg (ap, int *); int *n = va_arg (ap, int *);
@ -192,6 +259,8 @@ vfprintf (FILE * f, char const *format, va_list ap)
{ {
eputs ("vfprintf: not supported: %:"); eputs ("vfprintf: not supported: %:");
eputc (c); eputc (c);
eputs (", in format: ");
eputs (format);
eputs ("\n"); eputs ("\n");
p++; p++;
} }

208
lib/stdio/vfscanf.c Normal file
View File

@ -0,0 +1,208 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018,2019 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 <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int
vfscanf (FILE * stream, char const *template, va_list ap)
{
char r = fgetc (stream);
char const *t = template;
int count = 0;
while (*t && r != EOF)
if (*t != '%')
{
t++;
r = fgetc (stream);
}
else
{
t++;
char c = *t;
int skip_p = 0;
int length = -1;
if (c == '*')
skip_p = 1;
if (c >= '0' && c <= '9')
{
length = abtol (&t, 10);
c = *t;
}
if (c == 'l')
c = *++t;
switch (c)
{
case '%':
{
r = fgetc (stream);
break;
}
case 'c':
{
r = fgetc (stream);
if (!skip_p)
{
char *c = va_arg (ap, char *);
*c = r;
count++;
}
break;
}
case 'd':
case 'i':
case 'u':
{
int *d = skip_p ? 0 : va_arg (ap, int *);
char buf[20];
char *q = buf;
if (r == '+' || r == '-')
{
*q++ = r;
r = fgetc (stream);
}
while (isdigit (r))
{
*q++ = r;
r = fgetc (stream);
}
ungetc (r, stream);
*q = 0;
q = buf;
if (skip_p)
abtol ((char const **) &q, 10);
else
{
*d = abtol ((char const **) &q, 10);
count++;
}
break;
}
case 'e':
case 'f':
case 'g':
case 'E':
case 'G':
{
float *f = skip_p ? 0 : va_arg (ap, float *);
char buf[20];
char *q = buf;
if (r == '+' || r == '-')
{
*q++ = r;
r = fgetc (stream);
}
while (isdigit (r))
{
*q++ = r;
r = fgetc (stream);
}
ungetc (r, stream);
*q = 0;
q = buf;
if (skip_p)
strtod (q, &q);
else
{
*f = strtod (q, &q);
count++;
}
break;
}
case 's':
{
char *s = skip_p ? 0 : va_arg (ap, char *);
while (r && !isspace (r) && (length == -1 || length--))
{
if (!skip_p)
*s++ = r;
r = fgetc (stream);
}
if (!skip_p)
{
count++;
*s = 0;
}
break;
}
case '[':
{
char *s = skip_p ? 0 : va_arg (ap, char *);
char set[1024];
int i = 0;
int not_in_set_p = 0;
t++;
if (*t == '^')
{
not_in_set_p = 1;
t++;
}
if (*t == ']' || *t == '-')
set[i++] = *t++;
while (*t && *t != ']')
{
if (*t == '-')
{
char end = *t++;
for (char x = set[i - 1] + 1; x < end; x++)
set[i++] = x;
}
else
set[i++] = *t++;
}
set[i] = 0;
while (r && (length == -1 || length--))
{
int match = (int) (long) strchr (set, r);
if (not_in_set_p)
match = !match;
if (!match)
break;
if (!skip_p)
*s++ = r;
r = fgetc (stream);
}
if (!skip_p)
{
count++;
*s = 0;
}
break;
}
default:
{
eputs ("vsscanf: not supported: %:");
eputc (c);
eputs (", in template: ");
eputs (template);
eputs ("\n");
t++;
r = fgetc (stream);
}
}
t++;
}
va_end (ap);
return count;
}

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -43,6 +43,7 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
c = *p; c = *p;
int left_p = 0; int left_p = 0;
int precision = -1; int precision = -1;
int prefix_p = 0;
int width = -1; int width = -1;
if (c == '-') if (c == '-')
{ {
@ -50,10 +51,20 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
c = *++p; c = *++p;
} }
char pad = ' '; char pad = ' ';
if (c == ' ')
{
pad = c;
c = *++p;
}
if (c == '#')
{
prefix_p = 1;
c = *++p;
}
if (c == '0') if (c == '0')
{ {
pad = c; pad = c;
c = *p++; c = *++p;
} }
if (c >= '0' && c <= '9') if (c >= '0' && c <= '9')
{ {
@ -114,7 +125,7 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
{ {
long d = va_arg (ap, long); long d = va_arg (ap, long);
int base = c == 'o' ? 8 : c == 'x' || c == 'X' ? 16 : 10; int base = c == 'o' ? 8 : c == 'x' || c == 'X' ? 16 : 10;
char const *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X'); char *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X');
if (c == 'X') if (c == 'X')
strupr (s); strupr (s);
int length = strlen (s); int length = strlen (s);
@ -137,6 +148,18 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
count++; count++;
} }
} }
if (prefix_p && *s && c == 'o')
{
*s++ = '0';
width--;
}
if (prefix_p && *s && (c == 'x' || c == 'X'))
{
*s++ = '0';
width--;
*s++ = 'x';
width--;
}
while (*s) while (*s)
{ {
if (precision-- <= 0) if (precision-- <= 0)
@ -198,6 +221,55 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
} }
break; break;
} }
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
{
double d = va_arg8 (ap, double);
char *s = dtoab (d, 10, 1);
if (c == 'E' || c == 'G')
strupr (s);
int length = strlen (s);
if (precision == -1)
precision = length;
if (!left_p)
{
while (width-- > precision)
{
if (count < size)
*str++ = pad;
count++;
}
while (precision > length)
{
if (count < size)
*str++ = ' ';
precision--;
width--;
count++;
}
}
while (*s)
{
if (precision-- <= 0)
break;
width--;
c = *s++;
if (count < size)
*str++ = c;
count++;
}
while (width > 0)
{
width--;
if (count < size)
*str++ = pad;
count++;
}
break;
}
case 'n': case 'n':
{ {
int *n = va_arg (ap, int *); int *n = va_arg (ap, int *);
@ -208,6 +280,8 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
{ {
eputs ("vsnprintf: not supported: %:"); eputs ("vsnprintf: not supported: %:");
eputc (c); eputc (c);
eputs (", in format: ");
eputs (format);
eputs ("\n"); eputs ("\n");
p++; p++;
} }

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -41,6 +41,15 @@ vsscanf (char const *s, char const *template, va_list ap)
{ {
t++; t++;
char c = *t; char c = *t;
int skip_p = 0;
int length = -1;
if (c == '*')
skip_p = 1;
if (c >= '0' && c <= '9')
{
length = abtol (&t, 10);
c = *t;
}
if (c == 'l') if (c == 'l')
c = *++t; c = *++t;
switch (c) switch (c)
@ -52,24 +61,113 @@ vsscanf (char const *s, char const *template, va_list ap)
} }
case 'c': case 'c':
{ {
char *c = va_arg (ap, char *); char r = *p++;
*c = *p++; if (!skip_p)
count++; {
char *c = va_arg (ap, char *);
*c = r;
count++;
}
break; break;
} }
case 'd': case 'd':
case 'i': case 'i':
case 'u': case 'u':
{ {
int *d = va_arg (ap, int *); if (skip_p)
*d = abtol ((char const **)&p, 10); abtol ((char const **) &p, 10);
count++; else
{
int *d = va_arg (ap, int *);
*d = abtol ((char const **) &p, 10);
count++;
}
break;
}
case 'e':
case 'f':
case 'g':
case 'E':
case 'G':
{
if (skip_p)
strtod (p, &p);
else
{
float *f = va_arg (ap, float *);
*f = strtod (p, &p);
count++;
}
break;
}
case 's':
{
char *s = skip_p ? 0 : va_arg (ap, char *);
char r = *p;
while (r && !isspace (r) && (length == -1 || length--))
{
if (!skip_p)
*s++ = r;
r = *++p;
}
if (!skip_p)
{
count++;
*s = 0;
}
break;
}
case '[':
{
char *s = skip_p ? 0 : va_arg (ap, char *);
char set[1024];
int i = 0;
int not_in_set_p = 0;
t++;
if (*t == '^')
{
not_in_set_p = 1;
t++;
}
if (*t == ']' || *t == '-')
set[i++] = *t++;
while (*t && *t != ']')
{
if (*t == '-')
{
char end = *t++;
for (char x = set[i - 1] + 1; x < end; x++)
set[i++] = x;
}
else
set[i++] = *t++;
}
set[i] = 0;
char r = *p;
while (r && (length == -1 || length--))
{
int match = (int) (long) strchr (set, r);
if (not_in_set_p)
match = !match;
if (!match)
break;
if (!skip_p)
*s++ = r;
r = *++p;
}
if (!skip_p)
{
count++;
*s = 0;
}
break; break;
} }
default: default:
{ {
eputs ("vsscanf: not supported: %:"); eputs ("vsscanf: not supported: %:");
eputc (c); eputc (c);
eputs (", in template: ");
eputs (template);
eputs ("\n"); eputs ("\n");
t++; t++;
p++; p++;

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -18,6 +18,8 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdlib.h>
int int
__exit (int status) __exit (int status)
{ {

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -18,6 +18,8 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdlib.h>
void void
abort (void) abort (void)
{ {

View File

@ -25,4 +25,5 @@ int
atexit (void (*function) (void)) atexit (void (*function) (void))
{ {
__call_at_exit = function; __call_at_exit = function;
return 0;
} }

View File

@ -20,12 +20,9 @@
#include <mes/lib.h> #include <mes/lib.h>
int double
atof (int x) atof (char const *string)
{ {
static int stub = 0; char const *p = string;
if (__mes_debug () && !stub) return abtod (&p, 0);
eputs ("atof stub\n");
stub = 1;
return 0;
} }

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -21,8 +21,8 @@
#include <mes/lib.h> #include <mes/lib.h>
int int
atoi (char const *s) atoi (char const *string)
{ {
char const *p = s; char const *p = string;
return abtol (&p, 0); return abtol (&p, 0);
} }

View File

@ -18,10 +18,10 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <mes/lib.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#if !__MESC__
typedef char wchar_t[];
size_t size_t
mbstowcs (wchar_t * wstring, char const *string, size_t size) mbstowcs (wchar_t * wstring, char const *string, size_t size)
@ -33,4 +33,3 @@ mbstowcs (wchar_t * wstring, char const *string, size_t size)
strcpy (wstring, string); strcpy (wstring, string);
return strlen (string); return strlen (string);
} }
#endif

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -18,13 +18,15 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
void void
qswap (void *a, void *b, size_t size) qswap (void *a, void *b, size_t size)
{ {
char *buf[8]; char buf[128];
assert (size <= sizeof (buf));
memcpy (buf, a, size); memcpy (buf, a, size);
memcpy (a, b, size); memcpy (a, b, size);
memcpy (b, buf, size); memcpy (b, buf, size);

41
lib/stdlib/strtod.c Normal file
View File

@ -0,0 +1,41 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018,2019 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 <stdlib.h>
#include <string.h>
double
strtod (char const *string, char **tailptr)
{
int base = 10;
if (!strncmp (string, "0x", 2))
{
string += 2;
base = 16;
}
if (tailptr)
{
*tailptr = (char *) string;
return abtod ((char const **) tailptr, base);
}
char **p = (char **) &string;
return abtod ((char const **) p, base);
}

View File

@ -21,8 +21,15 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if BZERO_INT
int int
#else
void
#endif
bzero (void *block, size_t size) bzero (void *block, size_t size)
{ {
return (int) (long) memset (block, 0, size); #if BZERO_INT
return (int) (long)
#endif
memset (block, 0, size);
} }

View File

@ -20,8 +20,12 @@
#include <string.h> #include <string.h>
#if INDEX_INT
int int
#else
char *
#endif
index (char const *s, int c) index (char const *s, int c)
{ {
return (int) (long) strchr (s, c); return strchr (s, c);
} }

View File

@ -20,7 +20,11 @@
#include <string.h> #include <string.h>
#if INDEX_INT
int int
#else
char *
#endif
rindex (char const *s, int c) rindex (char const *s, int c)
{ {
return strrchr (s, c); return strrchr (s, c);

View File

@ -23,7 +23,7 @@
size_t size_t
strcspn (char const *string, char const *stopset) strcspn (char const *string, char const *stopset)
{ {
char *p = string; char *p = (char *) string;
while (*p) while (*p)
if (strchr (stopset, *p)) if (strchr (stopset, *p))
break; break;

View File

@ -23,7 +23,7 @@
char * char *
strpbrk (char const *string, char const *stopset) strpbrk (char const *string, char const *stopset)
{ {
char *p = string; char *p = (char *) string;
while (*p) while (*p)
if (strchr (stopset, *p)) if (strchr (stopset, *p))
break; break;

42
lib/string/strtok.c Normal file
View File

@ -0,0 +1,42 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <string.h>
char *
strtok (char *new_string, char const *delimiters)
{
static char *mark;
if (new_string)
mark = new_string;
if (!*mark)
return 0;
while (strchr (delimiters, *mark))
mark++;
char *point = mark;
while (*mark && !strchr (delimiters, *mark))
mark++;
if (*mark)
{
*mark = 0;
mark++;
}
return point;
}

34
lib/stub/asctime.c Normal file
View File

@ -0,0 +1,34 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <errno.h>
#include <time.h>
char *
asctime (struct tm const *broken_time)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("asctime stub\n");
stub = 1;
errno = 0;
return "now";
}

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -19,14 +19,14 @@
*/ */
#include <mes/lib.h> #include <mes/lib.h>
#include <stdlib.h> #include <math.h>
double double
strtod (char const *string, char **tailptr) atan2 (double x, double y)
{ {
static int stub = 0; static int stub = 0;
if (__mes_debug () && !stub) if (__mes_debug () && !stub)
eputs ("strtod stub\n"); eputs ("atan2 stub\n");
stub = 1; stub = 1;
return 0; return 0;
} }

32
lib/stub/cos.c Normal file
View File

@ -0,0 +1,32 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <math.h>
double
cos (double x)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("cos stub\n");
stub = 1;
return 0;
}

View File

@ -22,13 +22,13 @@
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
int char *
ctime (int x) ctime (time_t const *TIME)
{ {
static int stub = 0; static int stub = 0;
if (__mes_debug () && !stub) if (__mes_debug () && !stub)
eputs ("ctime stub\n"); eputs ("ctime stub\n");
stub = 1; stub = 1;
errno = 0; errno = 0;
return 0; return "now";
} }

32
lib/stub/exp.c Normal file
View File

@ -0,0 +1,32 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <math.h>
double
exp (double x)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("exp stub\n");
stub = 1;
return 0;
}

View File

@ -20,7 +20,7 @@
#include <mes/lib.h> #include <mes/lib.h>
int double
frexp (int x) frexp (int x)
{ {
static int stub = 0; static int stub = 0;

41
lib/stub/getgrgid.c Normal file
View File

@ -0,0 +1,41 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019 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 <errno.h>
#include <grp.h>
struct group *
getgrgid (gid_t gid)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("getgrid stub\n");
static char *groups[2] = { "root", 0 };
#if SYSTEM_LIBC
static struct group root = { "root", 0, 0 };
root.gr_mem = groups;
#else
static struct group root = { "root", 0, groups };
#endif
stub = 1;
errno = 0;
return &root;
}

41
lib/stub/getgrnam.c Normal file
View File

@ -0,0 +1,41 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019 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 <errno.h>
#include <grp.h>
struct group *
getgrnam (char const *name)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("getgrid stub\n");
static char *groups[2] = { "root", 0 };
#if SYSTEM_LIBC
static struct group root = { "root", 0, 0 };
root.gr_mem = groups;
#else
static struct group root = { "root", 0, groups };
#endif
stub = 1;
errno = 0;
return &root;
}

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -23,11 +23,12 @@
#include <unistd.h> #include <unistd.h>
int int
fscanf (FILE *stream, char const *template, ...) getpgid (pid_t pid)
{ {
static int stub = 0; static int stub = 0;
if (__mes_debug () && !stub) if (__mes_debug () && !stub)
eputs ("fscan stub\n"); eputs ("getpgid stub\n");
stub = 1; stub = 1;
errno = 0;
return 0; return 0;
} }

34
lib/stub/getpgrp.c Normal file
View File

@ -0,0 +1,34 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <errno.h>
#include <unistd.h>
pid_t
getpgrp (void)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("getpgrp stub\n");
stub = 1;
errno = 0;
return 0;
}

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -23,12 +23,13 @@
#include <pwd.h> #include <pwd.h>
struct passwd * struct passwd *
getpwnam (const char *NAME) getpwnam (const char *name)
{ {
static int stub = 0; static int stub = 0;
if (__mes_debug () && !stub) if (__mes_debug () && !stub)
eputs ("getpwnam stub\n"); eputs ("getpwnam stub\n");
stub = 1; stub = 1;
errno = 0; errno = 0;
return 0; static struct passwd root = { "root", "*", 0, 0, "", "/root", "/bin/sh" };
return &root;
} }

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -30,5 +30,6 @@ getpwuid (uid_t uid)
eputs ("getpwuid stub\n"); eputs ("getpwuid stub\n");
stub = 1; stub = 1;
errno = 0; errno = 0;
return 0; static struct passwd root = { "root", "*", 0, 0, "", "/root", "/bin/sh" };
return &root;
} }

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -22,7 +22,7 @@
#include <math.h> #include <math.h>
double double
ldexp (double x, int exp) ldexp (double value, int exponent)
{ {
static int stub = 0; static int stub = 0;
if (__mes_debug () && !stub) if (__mes_debug () && !stub)

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -31,5 +31,6 @@ localtime (time_t const *timep)
eputs ("localtime stub\n"); eputs ("localtime stub\n");
stub = 1; stub = 1;
errno = 0; errno = 0;
return 0; static struct tm zero = { 0 };
return &zero;
} }

32
lib/stub/log.c Normal file
View File

@ -0,0 +1,32 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <math.h>
double
log (double x)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("log stub\n");
stub = 1;
return 0;
}

34
lib/stub/mktime.c Normal file
View File

@ -0,0 +1,34 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019 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 <errno.h>
#include <time.h>
time_t
mktime (struct tm *broken_time)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("mktime stub\n");
stub = 1;
errno = 0;
return 0;
}

32
lib/stub/modf.c Normal file
View File

@ -0,0 +1,32 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <math.h>
double
modf (double value, double *integer_part)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("modf stub\n");
stub = 1;
return 0;
}

32
lib/stub/pow.c Normal file
View File

@ -0,0 +1,32 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <math.h>
double
pow (double base, double power)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("pow stub\n");
stub = 1;
return 0;
}

32
lib/stub/setgrent.c Normal file
View File

@ -0,0 +1,32 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019 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 <errno.h>
void
setgrent (void)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("setgrent stub\n");
stub = 1;
errno = 0;
}

32
lib/stub/sin.c Normal file
View File

@ -0,0 +1,32 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <math.h>
double
sin (double x)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("sin stub\n");
stub = 1;
return 0;
}

32
lib/stub/sqrt.c Normal file
View File

@ -0,0 +1,32 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <math.h>
double
sqrt (double x)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("sqrt stub\n");
stub = 1;
return 0;
}

34
lib/tests/mes/90-abtod.c Normal file
View File

@ -0,0 +1,34 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <stdlib.h>
#include <stdio.h>
int
main ()
{
char *s = "1.2e3";
char *p = s;
double d = abtod (&p, 0);
printf ("%f\n", d);
return 0;
}

View File

@ -0,0 +1 @@
1200.000000

36
lib/tests/mes/90-dtoab.c Normal file
View File

@ -0,0 +1,36 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <stdlib.h>
int
main ()
{
double d = 1.23;
char *p = dtoab (d, 10, 1);
puts (p);
d = -3.14159265;
p = dtoab (d, 10, 1);
puts (p);
return 0;
}

View File

@ -0,0 +1,2 @@
1.23
-3.14159265

View File

@ -0,0 +1,28 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 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 "unistd.h"
int
main (int argc, char const *argv[])
{
execlp ("echo", "echo", "Hello", "World!", 0);
return 0;
}

View File

@ -0,0 +1 @@
Hello World!

View File

@ -0,0 +1,44 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <stdio.h>
#include <stdlib.h>
int
main ()
{
char buf[20];
int i = 0;
printf ("%3.6d\n", i);
sprintf (buf, "%3.6d", i);
puts (buf);
double d = 1;
printf ("%3.6f\n", d);
sprintf (buf, "%3.6f", d);
puts (buf);
printf ("%3.6g\n", d);
sprintf (buf, "%3.6g", d);
puts (buf);
return 0;
}

View File

@ -0,0 +1,6 @@
000000
000000
1.000000
1.000000
1
1

View File

@ -0,0 +1,50 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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 <stdio.h>
#include <string.h>
int
main ()
{
char buf_abc[20];
char buf_xxx[20];
char buf_0_9[20];
int i = sscanf ("@abcxxx x0", "@%5[a-bc]%s%[^0-9]", &buf_abc, &buf_xxx, &buf_0_9);
if (i != 3)
return 1;
eputs ("buf_abc=");
eputs (buf_abc);
eputs ("\n");
eputs ("buf_xxx=");
eputs (buf_xxx);
eputs ("\n");
eputs ("buf_0_9=");
eputs (buf_0_9);
eputs ("\n");
if (strcmp (buf_abc, "abc"))
return 2;
if (strcmp (buf_xxx, "xxx"))
return 3;
if (strcmp (buf_0_9, " x"))
return 4;
return 0;
}

Some files were not shown because too many files have changed in this diff Show More