* .gitignore: Update.
* build-aux/bootstrap.sh.in: Update.
* build-aux/build-mes.sh: Update.
* build-aux/check-mescc.sh: Update.
* lib/tests/assert/50-assert.c: Move from scaffold/tests/50-assert.c.
* lib/tests/dirent/90-readdir.c: Move from scaffold/tests/99-readdir.c.
* lib/tests/dirent/readdir.dir: Move from scaffold/tests/readdir.dir.
* lib/tests/io/90-stat.c: Move from scaffold/tests/92-stat.c.
* lib/tests/mes/30-oputs.c: Move from scaffold/tests/31-oputs.c.
* lib/tests/mes/50-itoa.c: Move from scaffold/tests/51-itoa.c.
* lib/tests/posix/90-unsetenv.c: Move from scaffold/tests/94-unsetenv.c.
* lib/tests/setjmp/80-setjmp.c: Move from scaffold/tests/80-setjmp.c.
* lib/tests/signal/90-signal.c: Move from scaffold/tests/95-signal.c.
* lib/tests/stdio/70-printf-hello.c: Move from scaffold/tests/70-printf-hello.c.
* lib/tests/stdio/70-printf-simple.c: Move from scaffold/tests/70-printf-simple.c.
* lib/tests/stdio/70-printf.c: Move from scaffold/tests/70-printf.c.
* lib/tests/stdio/80-sscanf.c: Move from scaffold/tests/87-sscanf.c.
* lib/tests/stdio/90-fopen-append.c: Move from scaffold/tests/98-fopen.c.
* lib/tests/stdio/90-fopen.c: Move from scaffold/tests/97-fopen.c.
* lib/tests/stdio/90-fread-fwrite.c: Move from scaffold/tests/93-fread-fwrite.c.
* lib/tests/stdio/90-fseek.c: Move from scaffold/tests/91-fseek.c.
* lib/tests/stdlib/50-getenv.c: Move from lib/tests/stdlib/getenv.c.
* lib/tests/stdlib/50-malloc.c: Move from lib/tests/stdlib/malloc.c.
* lib/tests/stdlib/70-strtoull.c: Move from scaffold/tests/7j-strtoull.c.
* lib/tests/stdlib/80-qsort-dupes.c: Move from scaffold/tests/81-qsort-dupes.c.
* lib/tests/stdlib/80-qsort.c: Move from scaffold/tests/81-qsort.c.
* lib/tests/stdlib/90-strtol.c: Move from scaffold/tests/96-strto.c.
* lib/tests/string/30-strlen.c: Move from scaffold/tests/30-strlen.c.
* lib/tests/string/50-strcmp.c: Move from scaffold/tests/51-strcmp.c.
* lib/tests/string/50-strcpy.c: Move from scaffold/tests/53-strcpy.c.
* lib/tests/string/50-strncmp.c: Move from scaffold/tests/51-strncmp.c.
* lib/tests/string/70-strchr.c: Move from scaffold/tests/70-strchr.c.
* lib/tests/string/80-strncpy.c: Move from scaffold/tests/86-strncpy.c.
* lib/tests/string/80-strrchr.c: Move from scaffold/tests/88-strrchr.c.
* lib/tests/string/90-snprintf.c: Move from scaffold/tests/9a-snprintf.c.
* lib/tests/string/90-strpbrk.c: Move from scaffold/tests/90-strpbrk.c.
* lib/tests/string/90-strspn.c: Move from scaffold/tests/90-strspn.c.
/lib/x86-mes/0exit-42
/lib/x86-mes/exit-42
+/lib/tests/*/[0-9a][0-9a-z]-*
+/lib/tests/*/x86-mes-*
+!/lib/tests/*/*.c
+!/lib/tests/*/*.exit
+!/lib/tests/*/*.stdout
+
/scaffold/argv
/scaffold/hello
/scaffold/main
/scaffold/x86_64-mes-*
/scaffold/tests/x86-mes-*
-/scaffold/tests/[0-9a][0-9a-z]-[^.]*
+/scaffold/tests/[0-9a][0-9a-z]-*
+/scaffold/tests/t.*
+!/scaffold/tests/*.c
+!/scaffold/tests/*.exit
+!/scaffold/tests/*.stdout
/src/mes.mes.symbols.h
/src/gc.mes.h
@GUILE@ -e main -L module scripts/mescc.scm -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/x86-mes-argv scaffold/argv.x86-mes-o -l c-mini
-@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o lib/tests/stdlib/malloc.x86-mes-o lib/tests/stdlib/malloc.c
+@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o lib/tests/stdlib/50-malloc.x86-mes-o lib/tests/stdlib/50-malloc.c
-@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o lib/tests/stdlib/getenv.x86-mes-o lib/tests/stdlib/getenv.c
+@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o lib/tests/posix/50-getenv.x86-mes-o lib/tests/posix/50-getenv.c
@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/micro-mes.x86-mes-o scaffold/micro-mes.c
compile scaffold/argv
(libc="-l c-mini" link scaffold/argv)
-[ "$mes_p" ] && compile lib/tests/stdlib/malloc
-[ "$mes_p" ] && link lib/tests/stdlib/malloc
+[ "$mes_p" ] && compile lib/tests/stdlib/50-malloc
+[ "$mes_p" ] && link lib/tests/stdlib/50-malloc
-[ "$mes_p" ] && compile lib/tests/stdlib/getenv
-[ "$mes_p" ] && link lib/tests/stdlib/getenv
+[ "$mes_p" ] && compile lib/tests/posix/50-getenv
+[ "$mes_p" ] && link lib/tests/posix/50-getenv
[ "$mes_p" ] && compile scaffold/micro-mes
test_sh=${test_sh-${srcdest}build-aux/test.sh}
tests="
-t
-00-exit-0
-01-return-0
-02-return-1
-03-call
-04-call-0
-05-call-1
-06-call-!1
-06-!call-1
-06-call-2
-06-call-string
-06-call-variable
-06-return-void
-07-include
-08-assign
-08-assign-negative
-08-assign-global
-10-if-0
-11-if-1
-12-if-==
-13-if-!=
-14-if-goto
-15-if-!f
-16-if-t
-17-compare-char
-17-compare-ge
-17-compare-gt
-17-compare-le
-17-compare-lt
-17-compare-unsigned-ge
-17-compare-unsigned-gt
-17-compare-unsigned-le
-17-compare-unsigned-lt
-17-compare-unsigned-char-le
-17-compare-unsigned-short-le
-17-compare-unsigned-long-le
-17-compare-and
-17-compare-or
-17-compare-and-or
-17-compare-assign
-17-compare-call
-18-assign-shadow
-20-while
-21-char[]-simple
-21-char[]
-22-while-char[]
-23-global-pointer-init-null
-23-global-pointer-init
-23-global-pointer-ref
-23-global-pointer-pointer-ref
-23-pointer-sub
-23-pointer
-30-strlen
-31-oputs
-32-call-wrap
-32-compare
-33-and-or
-34-pre-post
-35-compare-char
-36-compare-arithmetic
-37-compare-assign
-38-compare-call-2
-38-compare-call-3
-38-compare-call
-40-if-else
-41-?
-42-goto-label
-43-for-do-while
-44-switch
-44-switch-fallthrough
-44-switch-body-fallthrough
-45-void-call
-46-function-static
-47-function-expression
-48-global-static
-50-assert
-51-pointer-sub
-51-itoa
-51-strcmp
-51-strncmp
-53-strcpy
-54-argc
-54-argv
-55-char-array
-60-math
-61-array
-62-array
-63-struct
-63-struct-pointer
-63-struct-local
-63-struct-function
-63-struct-assign
-63-struct-array
-63-struct-array-assign
-63-struct-array-compare
-63-struct-cell
-64-make-cell
-65-read
-66-local-char-array
-70-strchr
-70-stdarg
-70-printf-hello
-70-printf-simple
-70-printf
-71-struct-array
-72-typedef-struct-def
-73-union-hello
-73-union
-74-multi-line-string
-75-struct-union
-76-pointer-arithmetic-pp
-76-pointer-arithmetic
-77-pointer-assign
-78-union-struct
-79-int-array-simple
-79-int-array
-7a-struct-char-array
-7b-struct-int-array-hello
-7b-struct-int-array-pointer
-7b-struct-int-array
-7c-dynarray
-7d-cast-char
-7e-struct-array-access
-7f-struct-pointer-arithmetic
-7g-struct-byte-word-field
-7h-struct-assign
-7i-struct-struct-simple
-7i-struct-struct
-7j-strtoull
-7k-empty-for
-7k-for-each-elem-simple
-7k-for-each-elem
-7l-struct-any-size-array-simple
-7l-struct-any-size-array
-7m-struct-char-array-assign
-7n-struct-struct-array
-7o-struct-pre-post-simple
-7o-struct-pre-post
-7p-struct-cast
-7q-bit-field-simple
-7q-bit-field
-7r-sign-extend
-7s-struct-short
-7s-unsigned-compare
-7t-function-destruct
-7u-double
-7u-long-long
-7u-?-expression
-7u-call-?
-7u-inc-byte-word
-7u-struct-func
-7u-struct-size10
-7u-vstack
-80-setjmp
-81-qsort
-81-qsort-dupes
-82-define
-83-heterogenoous-init
-84-struct-field-list
-85-sizeof
-86-strncpy
-87-sscanf
-88-strrchr
-90-strspn
-90-strpbrk
-91-fseek
-92-stat
-93-fread-fwrite
-94-unsetenv
-95-signal
-96-strto
-97-fopen
-98-fopen
-99-readdir
-9a-snprintf
-a0-call-trunc-char
-a0-call-trunc-short
-a0-call-trunc-int
-a0-math-divide-signed-negative
-a1-global-no-align
-a1-global-no-clobber
+scaffold/tests/t
+scaffold/tests/00-exit-0
+scaffold/tests/01-return-0
+scaffold/tests/02-return-1
+scaffold/tests/03-call
+scaffold/tests/04-call-0
+scaffold/tests/05-call-1
+scaffold/tests/06-call-!1
+scaffold/tests/06-!call-1
+scaffold/tests/06-call-2
+scaffold/tests/06-call-string
+scaffold/tests/06-call-variable
+scaffold/tests/06-return-void
+scaffold/tests/07-include
+scaffold/tests/08-assign
+scaffold/tests/08-assign-negative
+scaffold/tests/08-assign-global
+scaffold/tests/10-if-0
+scaffold/tests/11-if-1
+scaffold/tests/12-if-==
+scaffold/tests/13-if-!=
+scaffold/tests/14-if-goto
+scaffold/tests/15-if-!f
+scaffold/tests/16-if-t
+scaffold/tests/17-compare-char
+scaffold/tests/17-compare-ge
+scaffold/tests/17-compare-gt
+scaffold/tests/17-compare-le
+scaffold/tests/17-compare-lt
+scaffold/tests/17-compare-unsigned-ge
+scaffold/tests/17-compare-unsigned-gt
+scaffold/tests/17-compare-unsigned-le
+scaffold/tests/17-compare-unsigned-lt
+scaffold/tests/17-compare-unsigned-char-le
+scaffold/tests/17-compare-unsigned-short-le
+scaffold/tests/17-compare-unsigned-long-le
+scaffold/tests/17-compare-and
+scaffold/tests/17-compare-or
+scaffold/tests/17-compare-and-or
+scaffold/tests/17-compare-assign
+scaffold/tests/17-compare-call
+scaffold/tests/18-assign-shadow
+scaffold/tests/20-while
+scaffold/tests/21-char[]-simple
+scaffold/tests/21-char[]
+scaffold/tests/22-while-char[]
+scaffold/tests/23-global-pointer-init-null
+scaffold/tests/23-global-pointer-init
+scaffold/tests/23-global-pointer-ref
+scaffold/tests/23-global-pointer-pointer-ref
+scaffold/tests/23-pointer-sub
+scaffold/tests/23-pointer
+lib/tests/mes/30-oputs
+lib/tests/string/30-strlen
+scaffold/tests/32-call-wrap
+scaffold/tests/32-compare
+scaffold/tests/33-and-or
+scaffold/tests/34-pre-post
+scaffold/tests/35-compare-char
+scaffold/tests/36-compare-arithmetic
+scaffold/tests/37-compare-assign
+scaffold/tests/38-compare-call-2
+scaffold/tests/38-compare-call-3
+scaffold/tests/38-compare-call
+scaffold/tests/40-if-else
+scaffold/tests/41-?
+scaffold/tests/42-goto-label
+scaffold/tests/43-for-do-while
+scaffold/tests/44-switch
+scaffold/tests/44-switch-fallthrough
+scaffold/tests/44-switch-body-fallthrough
+scaffold/tests/45-void-call
+scaffold/tests/46-function-static
+scaffold/tests/47-function-expression
+scaffold/tests/48-global-static
+lib/tests/assert/50-assert
+lib/tests/mes/50-itoa
+lib/tests/posix/50-getenv
+lib/tests/string/50-strcmp
+lib/tests/string/50-strcpy
+lib/tests/string/50-strncmp
+scaffold/tests/51-pointer-sub
+scaffold/tests/54-argc
+scaffold/tests/54-argv
+scaffold/tests/55-char-array
+scaffold/tests/60-math
+scaffold/tests/61-array
+scaffold/tests/62-array
+scaffold/tests/63-struct
+scaffold/tests/63-struct-pointer
+scaffold/tests/63-struct-local
+scaffold/tests/63-struct-function
+scaffold/tests/63-struct-assign
+scaffold/tests/63-struct-array
+scaffold/tests/63-struct-array-assign
+scaffold/tests/63-struct-array-compare
+scaffold/tests/63-struct-cell
+scaffold/tests/64-make-cell
+scaffold/tests/65-read
+scaffold/tests/66-local-char-array
+scaffold/tests/70-stdarg
+lib/tests/stdio/70-printf-hello
+lib/tests/stdio/70-printf-simple
+lib/tests/stdio/70-printf
+lib/tests/stdlib/70-strtoull
+lib/tests/string/70-strchr
+scaffold/tests/71-struct-array
+scaffold/tests/72-typedef-struct-def
+scaffold/tests/73-union-hello
+scaffold/tests/73-union
+scaffold/tests/74-multi-line-string
+scaffold/tests/75-struct-union
+scaffold/tests/76-pointer-arithmetic-pp
+scaffold/tests/76-pointer-arithmetic
+scaffold/tests/77-pointer-assign
+scaffold/tests/78-union-struct
+scaffold/tests/79-int-array-simple
+scaffold/tests/79-int-array
+scaffold/tests/7a-struct-char-array
+scaffold/tests/7b-struct-int-array-hello
+scaffold/tests/7b-struct-int-array-pointer
+scaffold/tests/7b-struct-int-array
+scaffold/tests/7c-dynarray
+scaffold/tests/7d-cast-char
+scaffold/tests/7e-struct-array-access
+scaffold/tests/7f-struct-pointer-arithmetic
+scaffold/tests/7g-struct-byte-word-field
+scaffold/tests/7h-struct-assign
+scaffold/tests/7i-struct-struct-simple
+scaffold/tests/7i-struct-struct
+scaffold/tests/7k-empty-for
+scaffold/tests/7k-for-each-elem-simple
+scaffold/tests/7k-for-each-elem
+scaffold/tests/7l-struct-any-size-array-simple
+scaffold/tests/7l-struct-any-size-array
+scaffold/tests/7m-struct-char-array-assign
+scaffold/tests/7n-struct-struct-array
+scaffold/tests/7o-struct-pre-post-simple
+scaffold/tests/7o-struct-pre-post
+scaffold/tests/7p-struct-cast
+scaffold/tests/7q-bit-field-simple
+scaffold/tests/7q-bit-field
+scaffold/tests/7r-sign-extend
+scaffold/tests/7s-struct-short
+scaffold/tests/7s-unsigned-compare
+scaffold/tests/7t-function-destruct
+scaffold/tests/7u-double
+scaffold/tests/7u-long-long
+scaffold/tests/7u-?-expression
+scaffold/tests/7u-call-?
+scaffold/tests/7u-inc-byte-word
+scaffold/tests/7u-struct-func
+scaffold/tests/7u-struct-size10
+scaffold/tests/7u-vstack
+lib/tests/setjmp/80-setjmp
+lib/tests/stdio/80-sscanf
+lib/tests/stdlib/80-qsort
+lib/tests/stdlib/80-qsort-dupes
+lib/tests/string/80-strncpy
+lib/tests/string/80-strrchr
+scaffold/tests/82-define
+scaffold/tests/83-heterogenoous-init
+scaffold/tests/84-struct-field-list
+scaffold/tests/85-sizeof
+lib/tests/dirent/90-readdir
+lib/tests/io/90-stat
+lib/tests/posix/90-unsetenv
+lib/tests/signal/90-signal
+lib/tests/stdio/90-fopen
+lib/tests/stdio/90-fopen-append
+lib/tests/stdio/90-fread-fwrite
+lib/tests/stdio/90-fseek
+lib/tests/stdlib/90-strtol
+lib/tests/string/90-snprintf
+lib/tests/string/90-strpbrk
+lib/tests/string/90-strspn
+scaffold/tests/a0-call-trunc-char
+scaffold/tests/a0-call-trunc-short
+scaffold/tests/a0-call-trunc-int
+scaffold/tests/a0-math-divide-signed-negative
+scaffold/tests/a1-global-no-align
+scaffold/tests/a1-global-no-clobber
"
broken="$broken
-17-compare-unsigned-char-le
-17-compare-unsigned-short-le
-66-local-char-array
-a0-call-trunc-int
-a0-math-divide-signed-negative
+scaffold/tests/17-compare-unsigned-char-le
+scaffold/tests/17-compare-unsigned-short-le
+scaffold/tests/66-local-char-array
+scaffold/tests/a0-call-trunc-int
+scaffold/tests/a0-math-divide-signed-negative
"
if [ "$mes_arch" = "x86_64-gcc" ]; then
broken="$broken
-21-char[]
-41-?
-70-printf-stdarg
-70-printf-simple
-70-printf
-80-setjmp
-a1-global-no-align
+scaffold/tests/21-char[]
+scaffold/tests/41-?
+scaffold/tests/stdio/70-printf-stdarg
+scaffold/tests/stdio/70-printf-simple
+scaffold/tests/stdio/70-printf
+lib/tests/setjmp/80-setjmp
+scaffold/tests/a1-global-no-align
"
fi
pass=0
fail=0
total=0
-mkdir -p scaffold/tests
for t in $tests; do
- if [ -z "${t/[012][0-9]-*/}" ]; then
+ b=$(basename "$t")
+ if [ -z "${b/[012][0-9]-*/}" ]; then
libc=
- elif [ -z "${t/[34][0-9]-*/}" ]; then
+ elif [ -z "${b/[34][0-9]-*/}" ]; then
libc='-l c-mini'
- elif [ -z "${t/[78][0-9a-z]-*/}" ]; then
+ elif [ -z "${b/[78][0-9a-z]-*/}" ]; then
libc='-l c+tcc'
- elif [ -z "${t/9[0-9a-z]-*/}" ]; then
+ elif [ -z "${b/9[0-9a-z]-*/}" ]; then
libc='-l c+gnu'
else
libc='-l c'
fi
- sh $test_sh "scaffold/tests/$t" &> scaffold/tests/"$t".log
+ sh $test_sh "$t" &> "$t".log
r=$?
total=$((total+1))
if [ $r = 0 ]; then
r=0
[ -f "$t".exit ] && r=$(cat "$t".exit)
set +e
-$(dirname "$o")/${program_prefix}$(basename "$o") $ARGS > "$o".${program_prefix}stdout
+$(dirname "$o")/${program_prefix}$(basename "$o") $ARGS > "$o".${program_prefix}1 2> "$o".${program_prefix}2
m=$?
-cat "$o".${program_prefix}stdout
+cat "$o".${program_prefix}1
set -e
[ $m = $r ]
-if [ -f "$t".expect ]; then
- $DIFF -ub "$t".expect "$o".${program_prefix}stdout
+if [ -f "$t".stdout ]; then
+ $DIFF -ub "$t".stdout "$o".${program_prefix}1
fi
#if !___GNU__
-#include <string/memcpy.c>
-#include <stdlib/malloc.c>
#include <assert/assert.c>
+#include <stdlib/malloc.c>
+#include <string/memcpy.c>
#endif
#include <stdio/getchar.c>
#include <stdlib/free.c>
#include <stdlib/realloc.c>
-#include <stdlib/getenv.c>
-#include <stdlib/setenv.c>
+#include <posix/getenv.c>
#include <posix/isatty.c>
+#include <posix/setenv.c>
#include <posix/wait.c>
#include <posix/execv.c>
--- /dev/null
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2016,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 <stdlib.h>
+
+char *
+getenv (char const* s)
+{
+ char **p = environ;
+ int length = strlen (s);
+ while (*p)
+ {
+ if (!strncmp (s, *p, length) && *(*p + length) == '=')
+ return (*p + length + 1);
+ p++;
+ }
+ return 0;
+}
--- /dev/null
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2016,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 <stdlib.h>
+
+int
+setenv (char const* s, char const* v, int overwrite_p)
+{
+ char **p = environ;
+ int length = strlen (s);
+ while (*p)
+ {
+ if (!strncmp (s, *p, length) && *(*p + length) == '=')
+ break;
+ p++;
+ }
+ char *entry = malloc (length + strlen (v) + 2);
+ int end_p = *p == 0;
+ *p = entry;
+ strcpy (entry, s);
+ strcpy (entry + length, "=");
+ strcpy (entry + length + 1, v);
+ *(entry + length + strlen (v) + 2) = 0;
+ if (end_p)
+ *++p = 0;
+ return 0;
+}
+++ /dev/null
-/* -*-comment-start: "//";comment-end:""-*-
- * GNU Mes --- Maxwell Equations of Software
- * Copyright © 2016,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 <stdlib.h>
-
-char *
-getenv (char const* s)
-{
- char **p = environ;
- int length = strlen (s);
- while (*p)
- {
- if (!strncmp (s, *p, length) && *(*p + length) == '=')
- return (*p + length + 1);
- p++;
- }
- return 0;
-}
+++ /dev/null
-/* -*-comment-start: "//";comment-end:""-*-
- * GNU Mes --- Maxwell Equations of Software
- * Copyright © 2016,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 <stdlib.h>
-
-int
-setenv (char const* s, char const* v, int overwrite_p)
-{
- char **p = environ;
- int length = strlen (s);
- while (*p)
- {
- if (!strncmp (s, *p, length) && *(*p + length) == '=')
- break;
- p++;
- }
- char *entry = malloc (length + strlen (v) + 2);
- int end_p = *p == 0;
- *p = entry;
- strcpy (entry, s);
- strcpy (entry + length, "=");
- strcpy (entry + length + 1, v);
- *(entry + length + strlen (v) + 2) = 0;
- if (end_p)
- *++p = 0;
- return 0;
-}
--- /dev/null
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2017 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 <libmes.h>
+#include <assert.h>
+#include <stdio.h>
+
+int
+main ()
+{
+ int f;
+
+ puts ("\n");
+ puts ("t: assert (1) ?\n");
+ assert (1);
+
+ puts ("t: assert (f==0) ?\n");
+ assert (f==0);
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+
+#include <dirent.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+qsort_strcmp (void const* a, void const* b)
+{
+ return strcmp (*((char**) a), *((char**) b));
+}
+
+int
+main ()
+{
+ DIR *d = opendir ("lib/tests/dirent/readdir-fu");
+ if (d)
+ return 1;
+ if (errno != ENOENT)
+ return 2;
+
+ d = opendir ("lib/tests/dirent/90-readdir.c");
+ if (d)
+ return 3;
+ if (errno != ENOTDIR)
+ return 4;
+
+ errno = 0;
+ d = opendir ("lib/tests/dirent/readdir.dir");
+ if (!d)
+ return 5;
+
+ if (errno)
+ return 6;
+
+ int i = 0;
+ char* list[6] = {0};
+ struct dirent *entry = readdir (d);
+ if (!entry)
+ return 7;
+ oputs (entry->d_name);
+ oputs ("\n");
+ list[i++] = entry->d_name;
+
+ entry = readdir (d);
+ if (!entry)
+ return 8;
+ oputs (entry->d_name);
+ oputs ("\n");
+ list[i++] = entry->d_name;
+
+ entry = readdir (d);
+ if (!entry)
+ return 9;
+ oputs (entry->d_name);
+ oputs ("\n");
+ list[i++] = entry->d_name;
+
+ entry = readdir (d);
+ if (!entry)
+ return 10;
+ oputs (entry->d_name);
+ oputs ("\n");
+ list[i++] = entry->d_name;
+
+ entry = readdir (d);
+ if (!entry)
+ return 11;
+ oputs (entry->d_name);
+ oputs ("\n");
+ list[i++] = entry->d_name;
+
+ entry = readdir (d);
+ if (entry)
+ return 12;
+
+ oputs ("\nls:\n");
+ qsort (list, 5, sizeof (char*), qsort_strcmp);
+ for (int i = 0; i < 5; i++)
+ {
+ oputs (list[i]); oputs ("\n");
+ }
+
+ if (strcmp (list[0], "."))
+ return 13;
+
+ if (strcmp (list[4], "link"))
+ return 14;
+
+ return 0;
+}
--- /dev/null
+file
\ No newline at end of file
--- /dev/null
+/* -*-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 <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+
+
+#if __i386__
+#define stat xstat
+
+struct stat
+{
+ unsigned long st_dev;
+ unsigned long st_ino;
+ unsigned short st_mode;
+ unsigned short st_nlink;
+ unsigned short st_uid;
+ unsigned short st_gid;
+ unsigned long st_rdev;
+ long st_size;
+ unsigned int st_blksize;
+ unsigned int st_blocks;
+ long st_atime;
+ unsigned long st_atime_usec;
+ long st_mtime;
+ unsigned long st_mtime_usec;
+ long st_ctime;
+ unsigned long st_ctime_usec;
+ unsigned int __foo0;
+ unsigned int __foo1;
+};
+#endif
+
+int
+main ()
+{
+ // char buf[20];
+ // strcpy (buf, "Hello");
+ // eputs ("buf="); eputs (buf); eputs ("\n");
+ // strcat (buf, ", ");
+ // eputs ("buf="); eputs (buf); eputs ("\n");
+ // strncat (buf, "world!XXX", 6);
+ // eputs ("buf="); eputs (buf); eputs ("\n");
+ // if (strcmp (buf, "Hello, world!"))
+ // return 1;
+
+ // char *name = "boo";
+ // errno = 0;
+ // fprintf (stderr, "%s: %s\n", name, strerror (errno));
+ int fd = open ("COPYING", 0);
+
+ struct stat sbuf;
+
+ int r = fstat (fd, &sbuf);
+ if (r < 0)
+ return 1;
+
+ eputs ("st_dev="); eputs (itoa (sbuf.st_dev)); eputs ("\n");
+ eputs ("st_ino="); eputs (itoa (sbuf.st_ino)); eputs ("\n");
+ eputs ("st_mode="); eputs (itoa (sbuf.st_mode)); eputs ("\n");
+ eputs ("st_nlink="); eputs (itoa (sbuf.st_nlink)); eputs ("\n");
+ eputs ("st_uid="); eputs (itoa (sbuf.st_uid)); eputs ("\n");
+ eputs ("st_gid="); eputs (itoa (sbuf.st_gid)); eputs ("\n");
+ eputs ("st_rdev="); eputs (itoa (sbuf.st_rdev)); eputs ("\n");
+ eputs ("st_size="); eputs (itoa (sbuf.st_size)); eputs ("\n");
+
+ eputs ("st_blksize="); eputs (itoa (sbuf.st_blksize)); eputs ("\n");
+ eputs ("st_blocks="); eputs (itoa (sbuf.st_blocks)); eputs ("\n");
+
+ eputs ("st_atime="); eputs (itoa (sbuf.st_atime)); eputs ("\n");
+ //eputs ("st_atime_nsec="); eputs (itoa (sbuf.st_atime_nsec)); eputs ("\n");
+
+ eputs ("st_mtime="); eputs (itoa (sbuf.st_mtime)); eputs ("\n");
+ //eputs ("st_mtime_nsec="); eputs (itoa (sbuf.st_mtime_nsec)); eputs ("\n");
+
+ eputs ("st_ctime="); eputs (itoa (sbuf.st_ctime)); eputs ("\n");
+ //eputs ("st_ctime_nsec="); eputs (itoa (sbuf.st_ctime_nsec)); eputs ("\n");
+
+ eputs ("size:"); eputs (itoa (sizeof (struct stat))); eputs ("\n");
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes-mini.h>
+
+#if 0
+#include <linux/x86_64/syscall.h>
+
+#define _write _xwrite
+#define write xwrite
+#define strlen xstrlen
+#define oputs xoputs
+
+#if __GNUC__
+#define SYS_write "0x01"
+#define SYS_exit "0x3c"
+
+ssize_t
+_write (int filedes, void const *buffer, size_t size)
+{
+ long r;
+ asm (
+ "mov $"SYS_write",%%rax\n\t"
+ "mov %1,%%rdi\n\t"
+ "mov %2,%%rsi\n\t"
+ "mov %3,%%rdx\n\t"
+ "syscall \n\t"
+ "mov %%rax,%0\n\t"
+ : "=r" (r)
+ : "rm" (filedes), "rm" (buffer), "rm" (size)
+ : "rax", "rdi", "rsi", "rdx"
+ );
+ return r;
+}
+#else
+#define SYS_write 0x01
+#define SYS_exit 0x3c
+void
+_write (int filedes, void const *buffer, size_t size)
+{
+ asm ("mov____0x8(%rbp),%rdi !0x10");
+ asm ("mov____0x8(%rbp),%rsi !0x18");
+ asm ("mov____0x8(%rbp),%rdx !0x20");
+ asm ("mov____$i32,%rax SYS_write");
+
+ asm ("syscall");
+}
+#endif
+
+ssize_t
+write (int filedes, void const *buffer, size_t size)
+{
+ int r = _write (filedes, buffer, size);
+ if (r < 0)
+ {
+ errno = -r;
+ r = -1;
+ }
+ else
+ errno = 0;
+ return r;
+}
+
+size_t
+strlen (char const* s)
+{
+ int i = 0;
+ while (s[i])
+ i++;
+ return i;
+}
+
+int
+oputs (char const* s)
+{
+ int i = strlen (s);
+ write (1, s, i);
+ return 0;
+}
+#endif
+
+int
+main ()
+{
+ oputs ("\n");
+ oputs ("mes\n");
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+#include <string.h>
+
+int
+main ()
+{
+ char *p = "mes";
+
+ oputs ("\n");
+ oputs ("t: itoa (33) == \"33\"\n");
+ oputs ("=>"); oputs (itoa (33)); oputs ("\n");
+
+ if (strcmp (itoa (33), "33"))
+ return 1;
+
+ oputs ("strcmp (itoa (-1), \"-1\")\n");
+ oputs (itoa (-1));
+ if (strcmp (itoa (-1), "-1"))
+ return 2;
+
+ oputs ("strcmp (itoa (0), \"0\")\n");
+ if (strcmp (itoa (0), "0"))
+ return 3;
+
+ oputs ("strcmp (itoa (1), \"1\")\n");
+ if (strcmp (itoa (1), "1"))
+ return 4;
+
+ return 0;
+}
--- /dev/null
+/* -*-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 "libmes.h"
+#include "stdlib.h"
+
+int
+main (int argc, char const *argv[])
+{
+ eputs ("test:getenv\n");
+ if (getenv ("SHELL") == 0)
+ return 1;
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int
+main ()
+{
+ eputs ("setenv\n");
+ setenv ("FOO", "BAR", 1);
+ if (strcmp (getenv ("FOO"), "BAR"))
+ return 1;
+ eputs ("unsetenv\n");
+ unsetenv ("FOO");
+ if (getenv ("FOO"))
+ return 2;
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <setjmp.h>
+
+int foo;
+
+void
+second()
+{
+ if (foo++)
+ exit (1);
+ oputs ("second\n"); // prints
+ longjmp (buf, 1); // jumps back to where setjmp was called - making setjmp now return 1
+ exit (1);
+}
+
+void
+first ()
+{
+ second ();
+ oputs ("first\n"); // does not print
+ exit (2);
+}
+
+int
+main ()
+{
+ if (!setjmp (buf))
+ first (); // when executed, setjmp returned 0
+ else // when longjmp jumps back, setjmp returns 1
+ {
+ oputs ("main\n"); // prints
+ return 0;
+ }
+
+ return 3;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+int g_alarm_handled_p = 0;
+
+void
+handler (int signum)
+{
+#if __MESC__ && __x86_64__
+ asm ("mov____%rdi,0x8(%rbp) !0x10"); // FIXME: AMDCC
+#endif
+ eputs ("handle:"); eputs (itoa (signum)); eputs ("\n");
+ if (signum != SIGALRM)
+ exit (66);
+ g_alarm_handled_p = 1;
+ #if __x86_64__
+ exit (0);
+ #endif
+}
+
+int
+main (void)
+{
+ eputs ("pid_t="); eputs (itoa (sizeof (pid_t))); eputs ("\n");
+ signal (SIGALRM, handler);
+ kill (getpid (), SIGALRM);
+ if (!g_alarm_handled_p)
+ return 2;
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+int
+main ()
+{
+#if __GNUC__ && __x86_64__ && !POSIX
+ return 0;
+#endif
+ int i = 42;
+ char *s = "mes";
+ char buf[20];
+
+ printf ("i=%d\n", i);
+ sprintf (buf, "i=%d\n", i);
+ if (strcmp (buf, "i=42\n"))
+ return 1;
+
+ printf ("s=%s\n", s);
+ sprintf (buf, "s=%s\n", s);
+ if (strcmp (buf, "s=mes\n"))
+ return 2;
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+int
+main ()
+{
+#if __GNUC__ && __x86_64__ && !POSIX
+ return 0;
+#endif
+ char *s = "mes";
+ char c = 'm';
+ int i = 3;
+ char buf[20];
+
+ printf ("c=%c\n", c);
+ sprintf (buf, "c=%c\n", c);
+ if (strcmp (buf, "c=m\n"))
+ return 1;
+
+ if (i != 3)
+ return 2;
+
+ printf ("i=%d\n", i);
+ sprintf (buf, "i=%d\n", i);
+ if (strcmp (buf, "i=3\n"))
+ return 3;
+
+ printf ("s=%s\n", s);
+ sprintf (buf, "s=%s\n", s);
+ if (strcmp (buf, "s=mes\n"))
+ return 4;
+
+ sprintf (buf, "%u", -1);
+ eputs ("buf="); eputs (buf); eputs ("\n");
+
+#if __i386__
+ if (strcmp (buf, "4294967295"))
+ return 5;
+#elif __x86_64__
+ if (strcmp (buf, "18446744073709551615"))
+ return 6;
+#endif
+
+ sprintf (buf, ">>%o<<\n", 12);
+ eputs ("buf="); eputs (buf);
+ if (strcmp (buf, ">>14<<\n"))
+ return 7;
+
+ sprintf (buf, ">>%x<<\n", 12);
+ eputs ("buf="); eputs (buf);
+ if (strcmp (buf, ">>c<<\n"))
+ return 8;
+
+ sprintf (buf, ">>%X<<\n", 12);
+ eputs ("buf="); eputs (buf);
+ if (strcmp (buf, ">>C<<\n"))
+ return 9;
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+int
+main ()
+{
+#if __GNUC__ && __x86_64__
+ return 0;
+#endif
+ char *s = "mes";
+ char c = 'm';
+ int i = 3;
+ char buf[20];
+
+ printf ("c=%c\n", c);
+ sprintf (buf, "c=%c\n", c);
+ if (strcmp (buf, "c=m\n"))
+ return 1;
+
+ if (i != 3)
+ return 15;
+ printf ("i=%d\n", i);
+ sprintf (buf, "i=%d\n", i);
+ if (strcmp (buf, "i=3\n"))
+ return 2;
+
+ printf ("s=%s\n", s);
+ sprintf (buf, "s=%s\n", s);
+ if (strcmp (buf, "s=mes\n"))
+ return 3;
+
+ sprintf (buf, ">%3d<", 11);
+ eputs (buf); eputs ("\n");
+ if (strcmp (buf, "> 11<"))
+ return 4;
+
+ sprintf (buf, ">%03d<", 22);
+ eputs (buf); eputs ("\n");
+ if (strcmp (buf, ">022<"))
+ return 5;
+
+ sprintf (buf, ">%-10d<", 33);
+ eputs (buf); eputs ("\n");
+ if (strcmp (buf, ">33 <"))
+ return 6;
+
+ sprintf (buf, ">%0d<", 44);
+ eputs (buf); eputs ("\n");
+ if (strcmp (buf, ">44<"))
+ return 7;
+
+ printf (">>%.*s<<\n", 5, "hello, world");
+ printf (">>%.*s<<\n", 20, "hello, world");
+
+ printf (">>%.*s<<\n", 10, "foo");
+ printf (">>%*s<<\n", 10, "bar");
+ printf (">>%-*s<<\n", 10, "baz");
+
+ sprintf (buf, "%ld", 42);
+ eputs ("buf="); eputs (buf); eputs ("\n");
+ if (strcmp (buf, "42"))
+ return 8;
+
+ sprintf (buf, "%u", -1);
+ eputs ("buf="); eputs (buf); eputs ("\n");
+
+#if __i386__
+ if (strcmp (buf, "4294967295"))
+ return 9;
+#elif __x86_64__
+ if (strcmp (buf, "18446744073709551615"))
+ return 9;
+#endif
+
+ sprintf (buf, ">>%.5s<<\n", "hello, world");
+ eputs ("buf="); eputs (buf);
+ if (strcmp (buf, ">>hello<<\n"))
+ return 10;
+
+ sprintf (buf, ">>%.*s<<\n", 5, "hello, world");
+ eputs ("buf="); eputs (buf);
+ if (strcmp (buf, ">>hello<<\n"))
+ return 11;
+
+ sprintf (buf, ">>%.*s<<\n", 20, "hello, world");
+ eputs ("buf="); eputs (buf);
+ if (strcmp (buf, ">>hello, world<<\n"))
+ return 12;
+
+ sprintf (buf, ">>%.*s<<\n", 10, "foo");
+ eputs ("buf="); eputs (buf);
+ if (strcmp (buf, ">>foo<<\n"))
+ return 13;
+
+ sprintf (buf, ">>%*s<<\n", 10, "bar");
+ eputs ("buf="); eputs (buf);
+ if (strcmp (buf, ">> bar<<\n"))
+ return 14;
+
+ sprintf (buf, ">>%-*s<<\n", 10, "baz");
+ eputs ("buf="); eputs (buf);
+ if (strcmp (buf, ">>baz <<\n"))
+ return 15;
+
+ sprintf (buf, ">>%ld<<\n", 12);
+ eputs ("buf="); eputs (buf);
+ if (strcmp (buf, ">>12<<\n"))
+ return 16;
+
+ sprintf (buf, ">>%o<<\n", 12);
+ eputs ("buf="); eputs (buf);
+ if (strcmp (buf, ">>14<<\n"))
+ return 17;
+
+ sprintf (buf, ">>%x<<\n", 12);
+ eputs ("buf="); eputs (buf);
+ if (strcmp (buf, ">>c<<\n"))
+ return 18;
+
+ sprintf (buf, ">>%X<<\n", 12);
+ eputs ("buf="); eputs (buf);
+ if (strcmp (buf, ">>C<<\n"))
+ return 19;
+
+ int n;
+#if !__x86_64__
+ fprintf (stderr, "foo bar\n%n", &n);
+ if (n != 8)
+ return 20;
+#endif
+
+ sprintf (buf, "foo%nbar\n", &n);
+ eputs ("buf="); eputs (buf); eputs ("\n");
+ if (strcmp (buf, "foobar\n"))
+ return 21;
+ if (n != 3)
+ return 22;
+
+#if !__x86_64__
+ fprintf (stdout, "%12.8d\n", 12345);
+#endif
+
+ sprintf (buf, "%12.8d\n", 12345);
+ eputs ("buf="); eputs (buf); eputs ("\n");
+ if (strcmp (buf, " 00012345\n"))
+ return 23;
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+
+#include <stdio.h>
+#include <stdarg.h>
+
+int
+main ()
+{
+#if __GNUC__ && __x86_64__ && !POSIX
+ return 0;
+#endif
+ int i;
+ int r = sscanf ("42", "%d", &i);
+ if (r != 1)
+ return 1;
+ if (i != 42)
+ return 2;
+
+ char c;
+ r = sscanf ("foo bar", "foo%cbar", &c);
+ if (r != 1)
+ return 3;
+ if (c != ' ')
+ return 4;
+
+ return 0;
+}
--- /dev/null
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2018 Jeremiah Orians <jeremiah@pdp10.guru>
+ *
+ * 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 <libmes.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int main()
+{
+ FILE* test = fopen("tmp", "a+");
+ FILE* hold = fopen("tmp", "r");
+ int a;
+ int b;
+ int i = 1000;
+ do
+ {
+ a = fgetc(test);
+ b = fgetc(hold);
+ fprintf(stdout, "%c == %c\n", a, b);
+ if(i < 1000)
+ {
+ fflush(test);
+ fputc('a', test);
+ }
+ if(b == EOF) exit(EXIT_SUCCESS);
+ i = i + 1;
+ }while (a == b);
+ fprintf(stderr, "OOOPS you were not supposed to get here\n");
+ exit(EXIT_FAILURE);
+}
--- /dev/null
+/* -*-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 <libmes.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int
+dump (char const *name, char const* contents)
+{
+ unlink (name);
+ FILE *f = fopen (name, "w");
+ fwrite (contents, strlen (contents), 1, f);
+ fclose (f);
+}
+
+int
+main ()
+{
+ char *line = "The first line.\n";
+ char *contents = "The first line.\nThe second line.\nThe last line.\n";
+ char* end = "That's all folks!\n";
+
+ char *tmp = "foo";
+
+ dump (tmp, contents);
+
+ FILE *t = fopen (tmp, "r+");
+ if (t <= 0)
+ return 1;
+
+ char buf[80];
+ memset (buf, 0, sizeof (buf));
+ fread (buf, strlen (line), 1, t);
+ eputs ("buf="); eputs (buf); eputs ("\n");
+ if (strcmp (buf, line))
+ return 2;
+
+ fwrite (end, strlen (end), 1, t);
+
+ fseek (t, 0, SEEK_SET);
+ memset (buf, 0, sizeof (buf));
+ fread (buf, strlen (line), 1, t);
+ eputs ("buf="); eputs (buf); eputs ("\n");
+ if (strcmp (buf, line))
+ return 3;
+
+ tmp = "bar";
+ dump (tmp, contents);
+ t = fopen (tmp, "w+");
+ if (t <= 0)
+ return 4;
+
+ fwrite (end, strlen (end), 1, t);
+ fseek (t, 0, SEEK_SET);
+ memset (buf, 0, sizeof (buf));
+ fread (buf, strlen (end), 1, t);
+ eputs ("buf="); eputs (buf); eputs ("\n");
+ if (strcmp (buf, end))
+ return 5;
+
+ fwrite (end, strlen (end), 1, t);
+
+ fseek (t, 0, SEEK_SET);
+ memset (buf, 0, sizeof (buf));
+ fread (buf, strlen (end), 1, t);
+ if (strcmp (buf, end))
+ return 6;
+
+ tmp = "baz";
+ dump (tmp, contents);
+ t = fopen (tmp, "a+");
+ if (t <= 0)
+ return 7;
+
+ fwrite (end, strlen (end), 1, t);
+ fseek (t, 0, SEEK_SET);
+ memset (buf, 0, sizeof (buf));
+ fread (buf, strlen (line), 1, t);
+ eputs ("buf="); eputs (buf); eputs ("\n");
+ if (strcmp (buf, line))
+ return 8;
+
+ fwrite (end, strlen (end), 1, t);
+
+ fseek (t, 0, SEEK_SET);
+ fread (buf, strlen (line), 1, t);
+ eputs ("buf="); eputs (buf); eputs ("\n");
+ if (strcmp (buf, line))
+ return 9;
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int
+main ()
+{
+ char *temp = "COPYING.tmp";
+ char *new = "COPYING.new";
+
+ unlink (temp);
+ unlink (new);
+
+ FILE *t = fopen (temp, "wb+");
+ FILE *n = fopen (new, "wb");
+
+ char *header = "!<header>\n";
+ fwrite (header, strlen (header), 1, n);
+
+ char *data = "foo bar baz\n";
+ fwrite (data, strlen (data), 1, t);
+
+ fseek (t, 0, SEEK_END);
+ int size = ftell (t);
+ fprintf (stderr, " size=>%d\n", size);
+ fseek (t, 0, SEEK_SET);
+ char *p = (char*)malloc (size + 1);
+ fread (p, size, 1, t);
+ fwrite (p, size, 1, n);
+
+ char header_plus_data[200];
+ strcpy (header_plus_data, header);
+ strcat (header_plus_data, data);
+
+ FILE *test = fopen (new, "r");
+ char buf[200];
+ fflush (n);
+ fread (buf, strlen (header_plus_data), 1, test);
+ eputs ("buf="); eputs (buf); eputs ("\n");
+ if (strcmp (buf, header_plus_data))
+ return 1;
+
+ if (access (temp, R_OK))
+ return 22;
+
+ unlink (temp);
+
+ if (!access (temp, R_OK))
+ return 3;
+
+ unlink (new);
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+
+int
+main ()
+{
+ int fd = open ("COPYING", 0);
+ if (fd <= 0)
+ return 1;
+ FILE* f = fdopen (fd, "r");
+ int r = fseek (f, 0, SEEK_CUR);
+ if (r != 0)
+ return 2;
+ int pos = ftell (f);
+ if (pos != 0)
+ return 3;
+
+ r = fseek (f, 0, SEEK_END);
+ if (r != 0)
+ return 4;
+
+ pos = ftell (f);
+ eputs ("size="); eputs (itoa (pos)); eputs ("\n");
+ if (pos != 35147)
+ return 5;
+ r = fseek (f, 0, SEEK_SET);
+
+ char buf[4096];
+ fgets (buf, 200, f);
+ eputs ("buf:"); eputs (buf);
+ if (strcmp (buf, " GNU GENERAL PUBLIC LICENSE\n"))
+ return 6;
+
+ return 0;
+}
--- /dev/null
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2016,2017 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/>.
+ */
+
+#if POSIX
+#error "POSIX not supported"
+#endif
+
+#include <libmes.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main (int argc, char *argv[])
+{
+ int size = 5000;
+ oputs ("m!\n");
+ //int *p = 0;
+ char *p = 0;
+ p = malloc (size);
+ size = 5000;
+ oputs ("p=");
+ oputs (itoa (p));
+ oputs ("\n");
+ int i;
+ for (i = 0; i < size; i=i+1)
+ {
+ oputs ("set ");
+ oputs (itoa (i));
+ oputs ("\n");
+ p[i] = i;
+ }
+ for (i = 0; i < size; i=i+1)
+ {
+ oputs (itoa (i));
+ oputs (": ");
+ oputs (itoa (p[i]));
+ oputs ("\n");
+ }
+ return 0;
+}
--- /dev/null
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2017 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 <libmes.h>
+#include <libmes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+main ()
+{
+ char *p = "42foo\n";
+ int n = abtol (&p, 0);
+ if (n != 42) return 1;
+ eputs (p);
+ if (strcmp (p, "foo\n")) return 2;
+
+ p = "2azar\n";
+ n = strtoull (p, (char**)&p, 16);
+ if (n != 42) return 3;
+ eputs (p);
+ if (strcmp (p, "zar\n")) return 4;
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+#include <string.h>
+
+int
+qsort_strcmp (void const* a, void const* b)
+{
+ return strcmp (*((char**) a), *((char**) b));
+}
+
+int
+main ()
+{
+ char* list[3] = {"foo", "foo", 0 };
+ oputs ("\nls:\n");
+ qsort (list, 2, sizeof (char*), qsort_strcmp);
+ for (int i = 0; i < 2; i++)
+ {
+ oputs (list[i]); oputs ("\n");
+ }
+
+ return 0;
+}
--- /dev/null
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2017 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 <libmes.h>
+
+#include <string.h>
+
+int
+compare_int (void *a, void *b)
+{
+ eputs ("compare: "); eputs (itoa (*(int*)a)); eputs (" <? "); eputs (itoa (*(int*)b));
+ eputs (" => "); eputs (itoa (*(int*)a - *(int*)b)); eputs ("\n");
+ return *(int*)a - *(int*)b;
+}
+
+int
+main ()
+{
+ int lst[6] = {0, 5, 4, 3, 2, -1};
+ qsort (lst, 6, sizeof (int), compare_int);
+ for (int i = 0; i < 6; i++)
+ {
+ eputs (itoa (i)); eputs (":"); eputs (itoa (lst[i])); eputs ("\n");
+ }
+ if (lst[0] != -1) return 1;
+ if (lst[5] != 5) return 2;
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+#include <stdlib.h>
+
+int
+main ()
+{
+ eputs ("0x12\n");
+ if (strtol ("0x12", 0, 0) != 18)
+ 1;
+
+ eputs ("012\n");
+ if (strtol ("012", 0, 0) != 10)
+ 2;
+
+ eputs ("-1\n");
+ if (strtol ("-1", 0, 0) != -1)
+ 3;
+
+ eputs ("-1\n");
+ if (strtoul ("-1", 0, 0) != -1)
+ 4;
+
+ char *p = "16";
+ int n = strtol (p, (char **)&p, 0);
+ eputs ("p="); eputs (p); eputs ("\n");
+ if (*p != 0)
+ return 5;
+
+ p = "0x12";
+ n = strtol (p, (char **)&p, 0);
+ eputs ("p="); eputs (p); eputs ("\n");
+ if (*p != 0)
+ return 5;
+
+
+ return 0;
+}
+++ /dev/null
-/* -*-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 "libmes.h"
-#include "string.h"
-#include "stdlib.h"
-#define strlen xstrlen
-#define strncmp xstrncmp
-#define getenv xgetenv
-#include "lib/string/strlen.c"
-#include "lib/string/strncmp.c"
-#include "lib/stdlib/getenv.c"
-
-int
-main (int argc, char const *argv[])
-{
- eputs ("test:getenv\n");
- if (getenv ("SHELL") == 0)
- return 1;
- return 0;
-}
+++ /dev/null
-/* -*-comment-start: "//";comment-end:""-*-
- * GNU Mes --- Maxwell Equations of Software
- * Copyright © 2016,2017 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/>.
- */
-
-#if POSIX
-#error "POSIX not supported"
-#endif
-
-#include <libmes.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-int
-main (int argc, char *argv[])
-{
- int size = 5000;
- oputs ("m!\n");
- //int *p = 0;
- char *p = 0;
- p = malloc (size);
- size = 5000;
- oputs ("p=");
- oputs (itoa (p));
- oputs ("\n");
- int i;
- for (i = 0; i < size; i=i+1)
- {
- oputs ("set ");
- oputs (itoa (i));
- oputs ("\n");
- p[i] = i;
- }
- for (i = 0; i < size; i=i+1)
- {
- oputs (itoa (i));
- oputs (": ");
- oputs (itoa (p[i]));
- oputs ("\n");
- }
- return 0;
-}
--- /dev/null
+/* -*-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 <libmes-mini.h>
+
+int
+main ()
+{
+ if (strlen ("mes") == 3)
+ goto ok;
+ return 1;
+ ok:
+ if (strlen ("mes") != 3)
+ return 1;
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+
+#include <string.h>
+
+int
+main ()
+{
+ char *p = "mes";
+
+ oputs ("\n");
+ oputs ("t: if (strcmp (p, \"foo\"))\n");
+ if (!strcmp (p, "foo"))
+ return 1;
+
+ oputs ("t: if (strcmp (p, \"t.c\\n\"))\n");
+ if (strcmp (p, "mes"))
+ return 2;
+
+ oputs ("t: if (!strcmp (p, \"t.c\\n\"))\n");
+ if (!strcmp (p, "mes")) goto ok1;
+ return 3;
+ ok1:
+
+ oputs ("t: if (strcmp (p, \"foo\"))\n");
+ if (strcmp (p, "foo")) goto ok2;
+ return 4;
+ ok2:
+
+ oputs ("t: itoa (33) == \"33\"\n");
+ if (strcmp (itoa (33), "33"))
+ return 5;
+
+ oputs ("strcmp (itoa (-1), \"-1\")\n");
+ if (strcmp (itoa (-1), "-1"))
+ return 6;
+
+ oputs ("strcmp (itoa (0), \"0\")\n");
+ if (strcmp (itoa (0), "0"))
+ return 7;
+
+ oputs ("strcmp (itoa (1), \"1\")\n");
+ if (strcmp (itoa (1), "1"))
+ return 8;
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+#include <string.h>
+
+int
+main ()
+{
+ oputs ("\n");
+ oputs ("t: strcpy (buf, \"mes\")\n");
+ char buf[10];
+ strcpy (buf, "mes");
+ if (strcmp (buf, "mes"))
+ return 1;
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+#include <string.h>
+
+int
+main ()
+{
+ if (strncmp ("abc", "a", 1))
+ return 1;
+
+ if (!strncmp ("abc", "x", 1))
+ return 2;
+
+ if (strncmp ("abc", "", 0))
+ return 3;
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+#include <string.h>
+
+#define strchr xstrchr
+char *
+strchr (char const *s, int c)
+{
+ char const *p = s;
+ while (*p || !c)
+ {
+ if (c == *p)
+ return p;
+ p++;
+ }
+ return 0;
+}
+
+int
+main ()
+{
+ char *p = strchr ("hello", 'l');
+ if (!p)
+ return 1;
+ int i = p - "hello";
+ // int i;
+ // i = p - "hello";
+ if (i != 2)
+ return i;
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+#include <stdio.h>
+#include <string.h>
+
+int
+main ()
+{
+ puts ("\n");
+ char buf[10] = {0,0,0,0,0,0,0,0,0,0};
+ strncpy (buf, "mesxxx", 3);
+ puts ("buf:");
+ puts (buf);
+ puts ("\n");
+ if (strncmp (buf, "mes", 3))
+ return 1;
+
+ strncpy (buf, "m", 4);
+ if (buf[3])
+ return 2;
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <string.h>
+
+int
+main (int argc, char *argv[])
+{
+ char *string = "foo.bar";
+ char *p = strrchr (string, 0);
+ if (!p)
+ return 1;
+ if (strcmp (p, ""))
+ return 2;
+ p = strrchr (string, '.');
+ if (strcmp (p, ".bar"))
+ return 3;
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <libmes.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+int
+main ()
+{
+ int n = snprintf (0, 0, "%s", "0123456");
+ eputs ("***n="); eputs (itoa (n)); eputs ("\n");
+ exit(n != 7);
+
+ /* if (n) */
+ /* return 1; */
+ return 0;
+}
--- /dev/null
+/* -*-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 <stdio.h>
+
+int
+main ()
+{
+ char buf[100];
+ strcpy (buf, "foo");
+
+ strcat (buf, " bar");
+ eputs (buf); eputs ("\n");
+ if (strcmp (buf, "foo bar"))
+ return 1;
+
+ strncat (buf, " bazzzz", 4);
+ eputs (buf); eputs ("\n");
+ if (strcmp (buf, "foo bar baz"))
+ return 2;
+
+ char *p = strpbrk ("hello, world", " \t\n,.;!?");
+ if (strcmp (p, ", world"))
+ return 3;
+ eputs ("\n");
+
+ if (strspn ("hello, world", "abcdefghijklmnopqrstuvwxyz") != 5)
+ return 4;
+
+ if (strcspn ("hello, world", " \t\n,.;!?") != 5)
+ return 5;
+
+
+ return 0;
+}
--- /dev/null
+/* -*-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 <string.h>
+
+#define strspn xstrspn
+
+size_t
+strspn (char const *string, char const *skipset)
+{
+ char *p = string;
+ while (*p)
+ if (!strchr (skipset, *p))
+ break;
+ else
+ p++;
+ return p - string;
+}
+
+int
+main ()
+{
+ if (strspn ("hello, world", "abcdefghijklmnopqrstuvwxyz") != 5)
+ return 1;
+
+ if (strcspn ("hello, world", " \t\n,.;!?") != 5)
+ return 2;
+
+ return 0;
+}
+++ /dev/null
-/* -*-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 <libmes-mini.h>
-
-int
-main ()
-{
- if (strlen ("mes") == 3)
- goto ok;
- return 1;
- ok:
- if (strlen ("mes") != 3)
- return 1;
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes-mini.h>
-
-#if 0
-#include <linux/x86_64/syscall.h>
-
-#define _write _xwrite
-#define write xwrite
-#define strlen xstrlen
-#define oputs xoputs
-
-#if __GNUC__
-#define SYS_write "0x01"
-#define SYS_exit "0x3c"
-
-ssize_t
-_write (int filedes, void const *buffer, size_t size)
-{
- long r;
- asm (
- "mov $"SYS_write",%%rax\n\t"
- "mov %1,%%rdi\n\t"
- "mov %2,%%rsi\n\t"
- "mov %3,%%rdx\n\t"
- "syscall \n\t"
- "mov %%rax,%0\n\t"
- : "=r" (r)
- : "rm" (filedes), "rm" (buffer), "rm" (size)
- : "rax", "rdi", "rsi", "rdx"
- );
- return r;
-}
-#else
-#define SYS_write 0x01
-#define SYS_exit 0x3c
-void
-_write (int filedes, void const *buffer, size_t size)
-{
- asm ("mov____0x8(%rbp),%rdi !0x10");
- asm ("mov____0x8(%rbp),%rsi !0x18");
- asm ("mov____0x8(%rbp),%rdx !0x20");
- asm ("mov____$i32,%rax SYS_write");
-
- asm ("syscall");
-}
-#endif
-
-ssize_t
-write (int filedes, void const *buffer, size_t size)
-{
- int r = _write (filedes, buffer, size);
- if (r < 0)
- {
- errno = -r;
- r = -1;
- }
- else
- errno = 0;
- return r;
-}
-
-size_t
-strlen (char const* s)
-{
- int i = 0;
- while (s[i])
- i++;
- return i;
-}
-
-int
-oputs (char const* s)
-{
- int i = strlen (s);
- write (1, s, i);
- return 0;
-}
-#endif
-
-int
-main ()
-{
- oputs ("\n");
- oputs ("mes\n");
- return 0;
-}
+++ /dev/null
-/* -*-comment-start: "//";comment-end:""-*-
- * GNU Mes --- Maxwell Equations of Software
- * Copyright © 2017 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 <libmes.h>
-#include <assert.h>
-#include <stdio.h>
-
-int
-main ()
-{
- int f;
-
- puts ("\n");
- puts ("t: assert (1) ?\n");
- assert (1);
-
- puts ("t: assert (f==0) ?\n");
- assert (f==0);
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-#include <string.h>
-
-int
-main ()
-{
- char *p = "mes";
-
- oputs ("\n");
- oputs ("t: itoa (33) == \"33\"\n");
- oputs ("=>"); oputs (itoa (33)); oputs ("\n");
-
- if (strcmp (itoa (33), "33"))
- return 1;
-
- oputs ("strcmp (itoa (-1), \"-1\")\n");
- oputs (itoa (-1));
- if (strcmp (itoa (-1), "-1"))
- return 2;
-
- oputs ("strcmp (itoa (0), \"0\")\n");
- if (strcmp (itoa (0), "0"))
- return 3;
-
- oputs ("strcmp (itoa (1), \"1\")\n");
- if (strcmp (itoa (1), "1"))
- return 4;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-
-#include <string.h>
-
-int
-main ()
-{
- char *p = "mes";
-
- oputs ("\n");
- oputs ("t: if (strcmp (p, \"foo\"))\n");
- if (!strcmp (p, "foo"))
- return 1;
-
- oputs ("t: if (strcmp (p, \"t.c\\n\"))\n");
- if (strcmp (p, "mes"))
- return 2;
-
- oputs ("t: if (!strcmp (p, \"t.c\\n\"))\n");
- if (!strcmp (p, "mes")) goto ok1;
- return 3;
- ok1:
-
- oputs ("t: if (strcmp (p, \"foo\"))\n");
- if (strcmp (p, "foo")) goto ok2;
- return 4;
- ok2:
-
- oputs ("t: itoa (33) == \"33\"\n");
- if (strcmp (itoa (33), "33"))
- return 5;
-
- oputs ("strcmp (itoa (-1), \"-1\")\n");
- if (strcmp (itoa (-1), "-1"))
- return 6;
-
- oputs ("strcmp (itoa (0), \"0\")\n");
- if (strcmp (itoa (0), "0"))
- return 7;
-
- oputs ("strcmp (itoa (1), \"1\")\n");
- if (strcmp (itoa (1), "1"))
- return 8;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-#include <string.h>
-
-int
-main ()
-{
- if (strncmp ("abc", "a", 1))
- return 1;
-
- if (!strncmp ("abc", "x", 1))
- return 2;
-
- if (strncmp ("abc", "", 0))
- return 3;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-#include <string.h>
-
-int
-main ()
-{
- oputs ("\n");
- oputs ("t: strcpy (buf, \"mes\")\n");
- char buf[10];
- strcpy (buf, "mes");
- if (strcmp (buf, "mes"))
- return 1;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-
-int
-main ()
-{
-#if __GNUC__ && __x86_64__ && !POSIX
- return 0;
-#endif
- int i = 42;
- char *s = "mes";
- char buf[20];
-
- printf ("i=%d\n", i);
- sprintf (buf, "i=%d\n", i);
- if (strcmp (buf, "i=42\n"))
- return 1;
-
- printf ("s=%s\n", s);
- sprintf (buf, "s=%s\n", s);
- if (strcmp (buf, "s=mes\n"))
- return 2;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-
-int
-main ()
-{
-#if __GNUC__ && __x86_64__ && !POSIX
- return 0;
-#endif
- char *s = "mes";
- char c = 'm';
- int i = 3;
- char buf[20];
-
- printf ("c=%c\n", c);
- sprintf (buf, "c=%c\n", c);
- if (strcmp (buf, "c=m\n"))
- return 1;
-
- if (i != 3)
- return 2;
-
- printf ("i=%d\n", i);
- sprintf (buf, "i=%d\n", i);
- if (strcmp (buf, "i=3\n"))
- return 3;
-
- printf ("s=%s\n", s);
- sprintf (buf, "s=%s\n", s);
- if (strcmp (buf, "s=mes\n"))
- return 4;
-
- sprintf (buf, "%u", -1);
- eputs ("buf="); eputs (buf); eputs ("\n");
-
-#if __i386__
- if (strcmp (buf, "4294967295"))
- return 5;
-#elif __x86_64__
- if (strcmp (buf, "18446744073709551615"))
- return 6;
-#endif
-
- sprintf (buf, ">>%o<<\n", 12);
- eputs ("buf="); eputs (buf);
- if (strcmp (buf, ">>14<<\n"))
- return 7;
-
- sprintf (buf, ">>%x<<\n", 12);
- eputs ("buf="); eputs (buf);
- if (strcmp (buf, ">>c<<\n"))
- return 8;
-
- sprintf (buf, ">>%X<<\n", 12);
- eputs ("buf="); eputs (buf);
- if (strcmp (buf, ">>C<<\n"))
- return 9;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-
-int
-main ()
-{
-#if __GNUC__ && __x86_64__
- return 0;
-#endif
- char *s = "mes";
- char c = 'm';
- int i = 3;
- char buf[20];
-
- printf ("c=%c\n", c);
- sprintf (buf, "c=%c\n", c);
- if (strcmp (buf, "c=m\n"))
- return 1;
-
- if (i != 3)
- return 15;
- printf ("i=%d\n", i);
- sprintf (buf, "i=%d\n", i);
- if (strcmp (buf, "i=3\n"))
- return 2;
-
- printf ("s=%s\n", s);
- sprintf (buf, "s=%s\n", s);
- if (strcmp (buf, "s=mes\n"))
- return 3;
-
- sprintf (buf, ">%3d<", 11);
- eputs (buf); eputs ("\n");
- if (strcmp (buf, "> 11<"))
- return 4;
-
- sprintf (buf, ">%03d<", 22);
- eputs (buf); eputs ("\n");
- if (strcmp (buf, ">022<"))
- return 5;
-
- sprintf (buf, ">%-10d<", 33);
- eputs (buf); eputs ("\n");
- if (strcmp (buf, ">33 <"))
- return 6;
-
- sprintf (buf, ">%0d<", 44);
- eputs (buf); eputs ("\n");
- if (strcmp (buf, ">44<"))
- return 7;
-
- printf (">>%.*s<<\n", 5, "hello, world");
- printf (">>%.*s<<\n", 20, "hello, world");
-
- printf (">>%.*s<<\n", 10, "foo");
- printf (">>%*s<<\n", 10, "bar");
- printf (">>%-*s<<\n", 10, "baz");
-
- sprintf (buf, "%ld", 42);
- eputs ("buf="); eputs (buf); eputs ("\n");
- if (strcmp (buf, "42"))
- return 8;
-
- sprintf (buf, "%u", -1);
- eputs ("buf="); eputs (buf); eputs ("\n");
-
-#if __i386__
- if (strcmp (buf, "4294967295"))
- return 9;
-#elif __x86_64__
- if (strcmp (buf, "18446744073709551615"))
- return 9;
-#endif
-
- sprintf (buf, ">>%.5s<<\n", "hello, world");
- eputs ("buf="); eputs (buf);
- if (strcmp (buf, ">>hello<<\n"))
- return 10;
-
- sprintf (buf, ">>%.*s<<\n", 5, "hello, world");
- eputs ("buf="); eputs (buf);
- if (strcmp (buf, ">>hello<<\n"))
- return 11;
-
- sprintf (buf, ">>%.*s<<\n", 20, "hello, world");
- eputs ("buf="); eputs (buf);
- if (strcmp (buf, ">>hello, world<<\n"))
- return 12;
-
- sprintf (buf, ">>%.*s<<\n", 10, "foo");
- eputs ("buf="); eputs (buf);
- if (strcmp (buf, ">>foo<<\n"))
- return 13;
-
- sprintf (buf, ">>%*s<<\n", 10, "bar");
- eputs ("buf="); eputs (buf);
- if (strcmp (buf, ">> bar<<\n"))
- return 14;
-
- sprintf (buf, ">>%-*s<<\n", 10, "baz");
- eputs ("buf="); eputs (buf);
- if (strcmp (buf, ">>baz <<\n"))
- return 15;
-
- sprintf (buf, ">>%ld<<\n", 12);
- eputs ("buf="); eputs (buf);
- if (strcmp (buf, ">>12<<\n"))
- return 16;
-
- sprintf (buf, ">>%o<<\n", 12);
- eputs ("buf="); eputs (buf);
- if (strcmp (buf, ">>14<<\n"))
- return 17;
-
- sprintf (buf, ">>%x<<\n", 12);
- eputs ("buf="); eputs (buf);
- if (strcmp (buf, ">>c<<\n"))
- return 18;
-
- sprintf (buf, ">>%X<<\n", 12);
- eputs ("buf="); eputs (buf);
- if (strcmp (buf, ">>C<<\n"))
- return 19;
-
- int n;
-#if !__x86_64__
- fprintf (stderr, "foo bar\n%n", &n);
- if (n != 8)
- return 20;
-#endif
-
- sprintf (buf, "foo%nbar\n", &n);
- eputs ("buf="); eputs (buf); eputs ("\n");
- if (strcmp (buf, "foobar\n"))
- return 21;
- if (n != 3)
- return 22;
-
-#if !__x86_64__
- fprintf (stdout, "%12.8d\n", 12345);
-#endif
-
- sprintf (buf, "%12.8d\n", 12345);
- eputs ("buf="); eputs (buf); eputs ("\n");
- if (strcmp (buf, " 00012345\n"))
- return 23;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-#include <string.h>
-
-#define strchr xstrchr
-char *
-strchr (char const *s, int c)
-{
- char const *p = s;
- while (*p || !c)
- {
- if (c == *p)
- return p;
- p++;
- }
- return 0;
-}
-
-int
-main ()
-{
- char *p = strchr ("hello", 'l');
- if (!p)
- return 1;
- int i = p - "hello";
- // int i;
- // i = p - "hello";
- if (i != 2)
- return i;
-
- return 0;
-}
+++ /dev/null
-/* -*-comment-start: "//";comment-end:""-*-
- * GNU Mes --- Maxwell Equations of Software
- * Copyright © 2017 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 <libmes.h>
-#include <libmes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-int
-main ()
-{
- char *p = "42foo\n";
- int n = abtol (&p, 0);
- if (n != 42) return 1;
- eputs (p);
- if (strcmp (p, "foo\n")) return 2;
-
- p = "2azar\n";
- n = strtoull (p, (char**)&p, 16);
- if (n != 42) return 3;
- eputs (p);
- if (strcmp (p, "zar\n")) return 4;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <setjmp.h>
-
-int foo;
-
-void
-second()
-{
- if (foo++)
- exit (1);
- oputs ("second\n"); // prints
- longjmp (buf, 1); // jumps back to where setjmp was called - making setjmp now return 1
- exit (1);
-}
-
-void
-first ()
-{
- second ();
- oputs ("first\n"); // does not print
- exit (2);
-}
-
-int
-main ()
-{
- if (!setjmp (buf))
- first (); // when executed, setjmp returned 0
- else // when longjmp jumps back, setjmp returns 1
- {
- oputs ("main\n"); // prints
- return 0;
- }
-
- return 3;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-#include <string.h>
-
-int
-qsort_strcmp (void const* a, void const* b)
-{
- return strcmp (*((char**) a), *((char**) b));
-}
-
-int
-main ()
-{
- char* list[3] = {"foo", "foo", 0 };
- oputs ("\nls:\n");
- qsort (list, 2, sizeof (char*), qsort_strcmp);
- for (int i = 0; i < 2; i++)
- {
- oputs (list[i]); oputs ("\n");
- }
-
- return 0;
-}
+++ /dev/null
-/* -*-comment-start: "//";comment-end:""-*-
- * GNU Mes --- Maxwell Equations of Software
- * Copyright © 2017 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 <libmes.h>
-
-#include <string.h>
-
-int
-compare_int (void *a, void *b)
-{
- eputs ("compare: "); eputs (itoa (*(int*)a)); eputs (" <? "); eputs (itoa (*(int*)b));
- eputs (" => "); eputs (itoa (*(int*)a - *(int*)b)); eputs ("\n");
- return *(int*)a - *(int*)b;
-}
-
-int
-main ()
-{
- int lst[6] = {0, 5, 4, 3, 2, -1};
- qsort (lst, 6, sizeof (int), compare_int);
- for (int i = 0; i < 6; i++)
- {
- eputs (itoa (i)); eputs (":"); eputs (itoa (lst[i])); eputs ("\n");
- }
- if (lst[0] != -1) return 1;
- if (lst[5] != 5) return 2;
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-#include <stdio.h>
-#include <string.h>
-
-int
-main ()
-{
- puts ("\n");
- char buf[10] = {0,0,0,0,0,0,0,0,0,0};
- strncpy (buf, "mesxxx", 3);
- puts ("buf:");
- puts (buf);
- puts ("\n");
- if (strncmp (buf, "mes", 3))
- return 1;
-
- strncpy (buf, "m", 4);
- if (buf[3])
- return 2;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-
-#include <stdio.h>
-#include <stdarg.h>
-
-int
-main ()
-{
-#if __GNUC__ && __x86_64__ && !POSIX
- return 0;
-#endif
- int i;
- int r = sscanf ("42", "%d", &i);
- if (r != 1)
- return 1;
- if (i != 42)
- return 2;
-
- char c;
- r = sscanf ("foo bar", "foo%cbar", &c);
- if (r != 1)
- return 3;
- if (c != ' ')
- return 4;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <string.h>
-
-int
-main (int argc, char *argv[])
-{
- char *string = "foo.bar";
- char *p = strrchr (string, 0);
- if (!p)
- return 1;
- if (strcmp (p, ""))
- return 2;
- p = strrchr (string, '.');
- if (strcmp (p, ".bar"))
- return 3;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <stdio.h>
-
-int
-main ()
-{
- char buf[100];
- strcpy (buf, "foo");
-
- strcat (buf, " bar");
- eputs (buf); eputs ("\n");
- if (strcmp (buf, "foo bar"))
- return 1;
-
- strncat (buf, " bazzzz", 4);
- eputs (buf); eputs ("\n");
- if (strcmp (buf, "foo bar baz"))
- return 2;
-
- char *p = strpbrk ("hello, world", " \t\n,.;!?");
- if (strcmp (p, ", world"))
- return 3;
- eputs ("\n");
-
- if (strspn ("hello, world", "abcdefghijklmnopqrstuvwxyz") != 5)
- return 4;
-
- if (strcspn ("hello, world", " \t\n,.;!?") != 5)
- return 5;
-
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <string.h>
-
-#define strspn xstrspn
-
-size_t
-strspn (char const *string, char const *skipset)
-{
- char *p = string;
- while (*p)
- if (!strchr (skipset, *p))
- break;
- else
- p++;
- return p - string;
-}
-
-int
-main ()
-{
- if (strspn ("hello, world", "abcdefghijklmnopqrstuvwxyz") != 5)
- return 1;
-
- if (strcspn ("hello, world", " \t\n,.;!?") != 5)
- return 2;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <stdio.h>
-
-int
-main ()
-{
- int fd = open ("COPYING", 0);
- if (fd <= 0)
- return 1;
- FILE* f = fdopen (fd, "r");
- int r = fseek (f, 0, SEEK_CUR);
- if (r != 0)
- return 2;
- int pos = ftell (f);
- if (pos != 0)
- return 3;
-
- r = fseek (f, 0, SEEK_END);
- if (r != 0)
- return 4;
-
- pos = ftell (f);
- eputs ("size="); eputs (itoa (pos)); eputs ("\n");
- if (pos != 35147)
- return 5;
- r = fseek (f, 0, SEEK_SET);
-
- char buf[4096];
- fgets (buf, 200, f);
- eputs ("buf:"); eputs (buf);
- if (strcmp (buf, " GNU GENERAL PUBLIC LICENSE\n"))
- return 6;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/stat.h>
-
-
-#if __i386__
-#define stat xstat
-
-struct stat
-{
- unsigned long st_dev;
- unsigned long st_ino;
- unsigned short st_mode;
- unsigned short st_nlink;
- unsigned short st_uid;
- unsigned short st_gid;
- unsigned long st_rdev;
- long st_size;
- unsigned int st_blksize;
- unsigned int st_blocks;
- long st_atime;
- unsigned long st_atime_usec;
- long st_mtime;
- unsigned long st_mtime_usec;
- long st_ctime;
- unsigned long st_ctime_usec;
- unsigned int __foo0;
- unsigned int __foo1;
-};
-#endif
-
-int
-main ()
-{
- // char buf[20];
- // strcpy (buf, "Hello");
- // eputs ("buf="); eputs (buf); eputs ("\n");
- // strcat (buf, ", ");
- // eputs ("buf="); eputs (buf); eputs ("\n");
- // strncat (buf, "world!XXX", 6);
- // eputs ("buf="); eputs (buf); eputs ("\n");
- // if (strcmp (buf, "Hello, world!"))
- // return 1;
-
- // char *name = "boo";
- // errno = 0;
- // fprintf (stderr, "%s: %s\n", name, strerror (errno));
- int fd = open ("COPYING", 0);
-
- struct stat sbuf;
-
- int r = fstat (fd, &sbuf);
- if (r < 0)
- return 1;
-
- eputs ("st_dev="); eputs (itoa (sbuf.st_dev)); eputs ("\n");
- eputs ("st_ino="); eputs (itoa (sbuf.st_ino)); eputs ("\n");
- eputs ("st_mode="); eputs (itoa (sbuf.st_mode)); eputs ("\n");
- eputs ("st_nlink="); eputs (itoa (sbuf.st_nlink)); eputs ("\n");
- eputs ("st_uid="); eputs (itoa (sbuf.st_uid)); eputs ("\n");
- eputs ("st_gid="); eputs (itoa (sbuf.st_gid)); eputs ("\n");
- eputs ("st_rdev="); eputs (itoa (sbuf.st_rdev)); eputs ("\n");
- eputs ("st_size="); eputs (itoa (sbuf.st_size)); eputs ("\n");
-
- eputs ("st_blksize="); eputs (itoa (sbuf.st_blksize)); eputs ("\n");
- eputs ("st_blocks="); eputs (itoa (sbuf.st_blocks)); eputs ("\n");
-
- eputs ("st_atime="); eputs (itoa (sbuf.st_atime)); eputs ("\n");
- //eputs ("st_atime_nsec="); eputs (itoa (sbuf.st_atime_nsec)); eputs ("\n");
-
- eputs ("st_mtime="); eputs (itoa (sbuf.st_mtime)); eputs ("\n");
- //eputs ("st_mtime_nsec="); eputs (itoa (sbuf.st_mtime_nsec)); eputs ("\n");
-
- eputs ("st_ctime="); eputs (itoa (sbuf.st_ctime)); eputs ("\n");
- //eputs ("st_ctime_nsec="); eputs (itoa (sbuf.st_ctime_nsec)); eputs ("\n");
-
- eputs ("size:"); eputs (itoa (sizeof (struct stat))); eputs ("\n");
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-int
-main ()
-{
- char *temp = "COPYING.tmp";
- char *new = "COPYING.new";
-
- unlink (temp);
- unlink (new);
-
- FILE *t = fopen (temp, "wb+");
- FILE *n = fopen (new, "wb");
-
- char *header = "!<header>\n";
- fwrite (header, strlen (header), 1, n);
-
- char *data = "foo bar baz\n";
- fwrite (data, strlen (data), 1, t);
-
- fseek (t, 0, SEEK_END);
- int size = ftell (t);
- fprintf (stderr, " size=>%d\n", size);
- fseek (t, 0, SEEK_SET);
- char *p = (char*)malloc (size + 1);
- fread (p, size, 1, t);
- fwrite (p, size, 1, n);
-
- char header_plus_data[200];
- strcpy (header_plus_data, header);
- strcat (header_plus_data, data);
-
- FILE *test = fopen (new, "r");
- char buf[200];
- fflush (n);
- fread (buf, strlen (header_plus_data), 1, test);
- eputs ("buf="); eputs (buf); eputs ("\n");
- if (strcmp (buf, header_plus_data))
- return 1;
-
- if (access (temp, R_OK))
- return 22;
-
- unlink (temp);
-
- if (!access (temp, R_OK))
- return 3;
-
- unlink (new);
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-int
-main ()
-{
- eputs ("setenv\n");
- setenv ("FOO", "BAR", 1);
- if (strcmp (getenv ("FOO"), "BAR"))
- return 1;
- eputs ("unsetenv\n");
- unsetenv ("FOO");
- if (getenv ("FOO"))
- return 2;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-int g_alarm_handled_p = 0;
-
-void
-handler (int signum)
-{
-#if __MESC__ && __x86_64__
- asm ("mov____%rdi,0x8(%rbp) !0x10"); // FIXME: AMDCC
-#endif
- eputs ("handle:"); eputs (itoa (signum)); eputs ("\n");
- if (signum != SIGALRM)
- exit (66);
- g_alarm_handled_p = 1;
- #if __x86_64__
- exit (0);
- #endif
-}
-
-int
-main (void)
-{
- eputs ("pid_t="); eputs (itoa (sizeof (pid_t))); eputs ("\n");
- signal (SIGALRM, handler);
- kill (getpid (), SIGALRM);
- if (!g_alarm_handled_p)
- return 2;
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-#include <stdlib.h>
-
-int
-main ()
-{
- eputs ("0x12\n");
- if (strtol ("0x12", 0, 0) != 18)
- 1;
-
- eputs ("012\n");
- if (strtol ("012", 0, 0) != 10)
- 2;
-
- eputs ("-1\n");
- if (strtol ("-1", 0, 0) != -1)
- 3;
-
- eputs ("-1\n");
- if (strtoul ("-1", 0, 0) != -1)
- 4;
-
- char *p = "16";
- int n = strtol (p, (char **)&p, 0);
- eputs ("p="); eputs (p); eputs ("\n");
- if (*p != 0)
- return 5;
-
- p = "0x12";
- n = strtol (p, (char **)&p, 0);
- eputs ("p="); eputs (p); eputs ("\n");
- if (*p != 0)
- return 5;
-
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-int
-dump (char const *name, char const* contents)
-{
- unlink (name);
- FILE *f = fopen (name, "w");
- fwrite (contents, strlen (contents), 1, f);
- fclose (f);
-}
-
-int
-main ()
-{
- char *line = "The first line.\n";
- char *contents = "The first line.\nThe second line.\nThe last line.\n";
- char* end = "That's all folks!\n";
-
- char *tmp = "foo";
-
- dump (tmp, contents);
-
- FILE *t = fopen (tmp, "r+");
- if (t <= 0)
- return 1;
-
- char buf[80];
- memset (buf, 0, sizeof (buf));
- fread (buf, strlen (line), 1, t);
- eputs ("buf="); eputs (buf); eputs ("\n");
- if (strcmp (buf, line))
- return 2;
-
- fwrite (end, strlen (end), 1, t);
-
- fseek (t, 0, SEEK_SET);
- memset (buf, 0, sizeof (buf));
- fread (buf, strlen (line), 1, t);
- eputs ("buf="); eputs (buf); eputs ("\n");
- if (strcmp (buf, line))
- return 3;
-
- tmp = "bar";
- dump (tmp, contents);
- t = fopen (tmp, "w+");
- if (t <= 0)
- return 4;
-
- fwrite (end, strlen (end), 1, t);
- fseek (t, 0, SEEK_SET);
- memset (buf, 0, sizeof (buf));
- fread (buf, strlen (end), 1, t);
- eputs ("buf="); eputs (buf); eputs ("\n");
- if (strcmp (buf, end))
- return 5;
-
- fwrite (end, strlen (end), 1, t);
-
- fseek (t, 0, SEEK_SET);
- memset (buf, 0, sizeof (buf));
- fread (buf, strlen (end), 1, t);
- if (strcmp (buf, end))
- return 6;
-
- tmp = "baz";
- dump (tmp, contents);
- t = fopen (tmp, "a+");
- if (t <= 0)
- return 7;
-
- fwrite (end, strlen (end), 1, t);
- fseek (t, 0, SEEK_SET);
- memset (buf, 0, sizeof (buf));
- fread (buf, strlen (line), 1, t);
- eputs ("buf="); eputs (buf); eputs ("\n");
- if (strcmp (buf, line))
- return 8;
-
- fwrite (end, strlen (end), 1, t);
-
- fseek (t, 0, SEEK_SET);
- fread (buf, strlen (line), 1, t);
- eputs ("buf="); eputs (buf); eputs ("\n");
- if (strcmp (buf, line))
- return 9;
-
- return 0;
-}
+++ /dev/null
-/* -*-comment-start: "//";comment-end:""-*-
- * GNU Mes --- Maxwell Equations of Software
- * Copyright © 2018 Jeremiah Orians <jeremiah@pdp10.guru>
- *
- * 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 <libmes.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-int main()
-{
- FILE* test = fopen("tmp", "a+");
- FILE* hold = fopen("tmp", "r");
- int a;
- int b;
- int i = 1000;
- do
- {
- a = fgetc(test);
- b = fgetc(hold);
- fprintf(stdout, "%c == %c\n", a, b);
- if(i < 1000)
- {
- fflush(test);
- fputc('a', test);
- }
- if(b == EOF) exit(EXIT_SUCCESS);
- i = i + 1;
- }while (a == b);
- fprintf(stderr, "OOOPS you were not supposed to get here\n");
- exit(EXIT_FAILURE);
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-
-#include <dirent.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-int
-qsort_strcmp (void const* a, void const* b)
-{
- return strcmp (*((char**) a), *((char**) b));
-}
-
-int
-main ()
-{
- DIR *d = opendir ("scaffold/tests/readdir-fu");
- if (d)
- return 1;
- if (errno != ENOENT)
- return 2;
-
- d = opendir ("scaffold/tests/99-readdir.c");
- if (d)
- return 3;
- if (errno != ENOTDIR)
- return 4;
-
- errno = 0;
- d = opendir ("scaffold/tests/readdir.dir");
- if (!d)
- return 5;
-
- if (errno)
- return 6;
-
- int i = 0;
- char* list[6] = {0};
- struct dirent *entry = readdir (d);
- if (!entry)
- return 7;
- oputs (entry->d_name);
- oputs ("\n");
- list[i++] = entry->d_name;
-
- entry = readdir (d);
- if (!entry)
- return 8;
- oputs (entry->d_name);
- oputs ("\n");
- list[i++] = entry->d_name;
-
- entry = readdir (d);
- if (!entry)
- return 9;
- oputs (entry->d_name);
- oputs ("\n");
- list[i++] = entry->d_name;
-
- entry = readdir (d);
- if (!entry)
- return 10;
- oputs (entry->d_name);
- oputs ("\n");
- list[i++] = entry->d_name;
-
- entry = readdir (d);
- if (!entry)
- return 11;
- oputs (entry->d_name);
- oputs ("\n");
- list[i++] = entry->d_name;
-
- entry = readdir (d);
- if (entry)
- return 12;
-
- oputs ("\nls:\n");
- qsort (list, 5, sizeof (char*), qsort_strcmp);
- for (int i = 0; i < 5; i++)
- {
- oputs (list[i]); oputs ("\n");
- }
-
- if (strcmp (list[0], "."))
- return 13;
-
- if (strcmp (list[4], "link"))
- return 14;
-
- return 0;
-}
+++ /dev/null
-/* -*-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 <libmes.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-
-int
-main ()
-{
- int n = snprintf (0, 0, "%s", "0123456");
- eputs ("***n="); eputs (itoa (n)); eputs ("\n");
- exit(n != 7);
-
- /* if (n) */
- /* return 1; */
- return 0;
-}
+++ /dev/null
-file
\ No newline at end of file