diff --git a/build-aux/build-cc.sh b/build-aux/build-cc.sh index 0672c07a..a6544ebe 100755 --- a/build-aux/build-cc.sh +++ b/build-aux/build-cc.sh @@ -50,8 +50,4 @@ build-aux/mes-snarf.scm src/posix.c build-aux/mes-snarf.scm src/reader.c build-aux/mes-snarf.scm src/vector.c -NOLINK=1 sh build-aux/cc.sh lib/libc-mini-gcc -NOLINK=1 sh build-aux/cc.sh lib/libc-gcc -NOLINK=1 sh build-aux/cc.sh lib/libc+tcc-gcc - sh build-aux/cc.sh src/mes diff --git a/include/mlibc.h b/include/libmes.h similarity index 68% rename from include/mlibc.h rename to include/libmes.h index 2e4cfdaf..ac4f1879 100644 --- a/include/mlibc.h +++ b/include/libmes.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * Mes --- Maxwell Equations of Software - * Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen * * This file is part of Mes. * @@ -18,12 +18,21 @@ * along with Mes. If not, see . */ -#ifndef __MES_MLIBC_H -#define __MES_MLIBC_H +#ifndef __MES_LIBMES_H +#define __MES_LIBMES_H char const* itoa (int); +char const* itoab (int x, int base); int _atoi (char const**, int base); +int atoi (char const *s); int eputc (int c); int eputs (char const* s); +int fdgetc (int fd); +int fdputc (int c, int fd); +int fdputs (char const* s, int fd); +int fdungetc (int c, int fd); +int isdigit (int c); +int isspace (int c); +int isxdigit (int c); -#endif //__MES_MLIBC_H +#endif //__MES_LIBMES_H diff --git a/include/stdio.h b/include/stdio.h index c568ed6c..c7e55cfb 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -43,24 +43,6 @@ int g_stdout; #undef __MES_STDIO_H #include_next -int fdputs (char const* s, int fd); - -#undef puts -#define fputs fdputs - -#ifdef putc -#undef putc -#endif - -int eputc (int c); -int eputs (char const* s); -int fdputc (int c, int fd); -int getchar (); - -#define fputc fdputc -#define ungetc fdungetc -int fdungetc (int c, int fd); - #else // ! (__GNUC__ && POSIX) #ifndef EOF @@ -81,15 +63,6 @@ int fdungetc (int c, int fd); #define SEEK_CUR 1 #define SEEK_END 2 -#if __GNUC__ -#undef fputs -#undef fdputs -int fdputs (char const* s, int fd); -#endif // __MES_GNUC__ - -//#define fputs fdputs -//#define fputc fdputc - typedef int FILE; #ifndef __MES_SIZE_T @@ -98,39 +71,34 @@ typedef int FILE; typedef unsigned long size_t; #endif -int getc (FILE *stream); -int fputc (int c, FILE* stream); -int fdputs (char const* s, int fd); -int fputs (char const* s, FILE *stream); -int putc (int c, FILE* stream); -//int putc (int c, int fd); - +FILE *fdopen (int fd, char const *mode); +FILE *fopen (char const *file_name, char const *mode); int eputc (int c); int eputs (char const* s); int fclose (FILE *stream); -FILE *fdopen (int fd, char const *mode); -int fdputc (int c, int fd); -int fflush (FILE *stream); int ferror (FILE *stream); -FILE *fopen (char const *file_name, char const *mode); -int fpurge (FILE *stream); -//void __fpurge (FILE *stream); +int fflush (FILE *stream); +int fgetc (FILE* stream); int fprintf (FILE *stream, char const *format, ...); -size_t fread (void *ptr, size_t size, size_t nmemb, FILE *stream); -size_t __freadahead (FILE *fp); -//size_t freadahead (FILE *fp); +int fpurge (FILE *stream); +int fputc (int c, FILE *stream); +int fputs (char const* s, FILE *stream); int fseek (FILE *stream, long offset, int whence); -long ftell (FILE *stream); -size_t fwrite (void const *ptr, size_t size, size_t nmemb, FILE *stream); +int getc (FILE *stream); int getchar (); int printf (char const* format, ...); +int putc (int c, FILE* stream); int putchar (int c); int puts (char const* s); int remove (char const *file_name); -int sscanf (char const *str, const char *format, ...); int snprintf(char *str, size_t size, char const *format, ...); int sprintf (char *str, char const* format, ...); -int ungetc (int c, int fd); +int sscanf (char const *str, const char *format, ...); +int ungetc (int c, FILE* stream); +long ftell (FILE *stream); +size_t fread (void *ptr, size_t size, size_t count, FILE *stream); +size_t freadahead (FILE *fp); +size_t fwrite (void const *ptr, size_t size, size_t count, FILE *stream); #endif // ! (__GNUC__ && POSIX) diff --git a/lib/crt1.c b/lib/crt1.c index 77e6fbbe..9fadbb59 100644 --- a/lib/crt1.c +++ b/lib/crt1.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * Mes --- Maxwell Equations of Software - * Copyright © 2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen * * This file is part of Mes. * @@ -19,9 +19,9 @@ */ char **g_environment = 0; -int main (int,char*[]); +int main (int argc, char *argv[]); -#if __GNUC__ && !POSIX +#if __GNUC__ void _start () diff --git a/lib/libc+tcc-gcc.c b/lib/libc+tcc-gcc.c index f53480b2..87bb0ac8 100644 --- a/lib/libc+tcc-gcc.c +++ b/lib/libc+tcc-gcc.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * Mes --- Maxwell Equations of Software - * Copyright © 2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen * * This file is part of Mes. * @@ -33,8 +33,7 @@ #include #include #include - -#if !POSIX +#include int errno; @@ -150,7 +149,3 @@ __fixsfdi (double a1) eputs ("__fixsfdi stub\n"); return 0; } - -#include - -#endif // !POSIX diff --git a/lib/libc-gcc.c b/lib/libc-gcc.c index 1bcc0a7c..95c22667 100644 --- a/lib/libc-gcc.c +++ b/lib/libc-gcc.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * Mes --- Maxwell Equations of Software - * Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen * * This file is part of Mes. * @@ -18,10 +18,10 @@ * along with Mes. If not, see . */ -#include +#include #include -#include +#include #include #include #include @@ -32,45 +32,5 @@ #include #include #include +#include #include - -#if POSIX - -int -putchar (int c) -{ - write (STDOUT, (char*)&c, 1); - return 0; -} - -int ungetc_char = -1; -char ungetc_buf[2]; - -int -getchar () -{ - char c; - int i; - if (ungetc_char == -1) - { - int r = read (g_stdin, &c, 1); - if (r < 1) return -1; - i = c; - } - else - i = ungetc_buf[ungetc_char--]; - - if (i < 0) i += 256; - - return i; -} - -int -fdungetc (int c, int fd) -{ - assert (ungetc_char < 2); - ungetc_buf[++ungetc_char] = c; - return c; -} - -#endif // POSIX diff --git a/lib/libc-mes.c b/lib/libc-mes.c index 91fde8b2..9c9b08d9 100644 --- a/lib/libc-mes.c +++ b/lib/libc-mes.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * Mes --- Maxwell Equations of Software - * Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen * * This file is part of Mes. * @@ -18,7 +18,7 @@ * along with Mes. If not, see . */ -#include +#include #include #include #include @@ -28,4 +28,5 @@ void _env (); #include #include #include +#include #include diff --git a/lib/libc.c b/lib/libc.c index 8a8af86b..15afbcda 100644 --- a/lib/libc.c +++ b/lib/libc.c @@ -23,148 +23,6 @@ #include #include -#if POSIX -#define _GNU_SOURCE -#include -#include -#include -#include -#endif // POSIX - -int -isdigit (int c) -{ - return (c>='0') && (c<='9'); -} - -int -isxdigit (int c) -{ - return isdigit (c) || (c>='a') && (c<='f'); -} - -int -isspace (int c) -{ - return (c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r' || c == ' '); -} - -int -isnumber (int c, int base) -{ - if (base == 2) - return (c>='0') && (c<='1'); - if (base == 8) - return (c>='0') && (c<='7'); - if (base == 10) - return isdigit (c); - if (base == 16) - return isxdigit (c); -} - -int -abtoi (char const **p, int base) -{ - char const *s = *p; - int i = 0; - int sign = 1; - if (!base) base = 10; - if (*s && *s == '-') - { - sign = -1; - s++; - } - while (isnumber (*s, base)) - { - i *= base; - int m = *s > '9' ? 'a' - 10 : '0'; - i += *s - m; - s++; - } - *p = s; - return i * sign; -} - -int -atoi (char const *s) -{ - char const *p = s; - return abtoi (&p, 0); -} - -char const* -itoa (int x) -{ - static char itoa_buf[12]; - char *p = itoa_buf + 11; - *p-- = 0; - - int sign = 0; - unsigned u = x; - if (x < 0) - { - sign = 1; - u = -x; - } - - do - { - *p-- = '0' + (u % 10); - u = u / 10; - } while (u); - - if (sign && *(p + 1) != '0') - *p-- = '-'; - - return p+1; -} - -char const* -itoab (int x, int base) -{ - static char itoa_buf[12]; - char *p = itoa_buf + 11; - *p-- = 0; - - int sign = 0; - unsigned u = x; - if (x < 0) - { - sign = 1; - u = -x; - } - - do - { - int i = u % base; - *p-- = i > 9 ? 'a' + i - 10 : '0' + i; - x = u / base; - } while (u); - - if (sign && *(p + 1) != '0') - *p-- = '-'; - - return p+1; -} - -int -fdputc (int c, int fd) -{ - write (fd, (char*)&c, 1); - return 0; -} - -int -fdputs (char const* s, int fd) -{ - int i = strlen (s); - write (fd, s, i); - return 0; -} - -#if !POSIX - -///char **g_environment = 0; // FIXME: todo extern int g_stdin = 0; void _env (); @@ -196,26 +54,19 @@ putc (int c, FILE* stream) FILE* fopen (char const* file_name, char const* mode) { - FILE* f; + int fd; if ('w' == mode[0]) /* 577 is O_WRONLY|O_CREAT|O_TRUNC, 384 is 600 in octal */ - f = open (file_name, 577 , 384); + fd = open (file_name, 577 , 384); else /* Everything else is a read */ - f = open (file_name, 0, 0); + fd = open (file_name, 0, 0); /* Negative numbers are error codes */ - if (0 > f) + if (fd > 0) return 0; - return f; -} - -int -putchar (int c) -{ - write (STDOUT, (char*)&c, 1); - return 0; + return (FILE*)fd; } void @@ -224,48 +75,21 @@ assert_fail (char* s) eputs ("assert fail: "); eputs (s); eputs ("\n"); - //*((int*)0) = 0; char *fail = s; fail = 0; *fail = 0; } -int ungetc_char = -1; -char ungetc_buf[2]; - int -getchar () +getc (FILE *stream) { - char c; - int i; - if (ungetc_char == -1) - { - int r = read (g_stdin, &c, 1); - if (r < 1) return -1; - i = c; - } - else - { - //FIXME - //i = ungetc_buf[ungetc_char--]; - i = ungetc_buf[ungetc_char]; - //ungetc_char--; - ungetc_char = ungetc_char - 1; - } - if (i < 0) i += 256; - - return i; + return fdgetc ((int)stream); } int -fgetc (int fd) +fgetc (FILE *stream) { - char c; - int i; - int r = read (fd, &c, 1); - if (r < 1) return -1; - i = c; - return i; + return fdgetc ((int)stream); } void @@ -273,18 +97,10 @@ free (void *ptr) { } -//#define assert(x) ((x) ? (void)0 : assert_fail (#x)) int -ungetc (int c, int fd) +ungetc (int c, FILE *stream) { - //FIXME - //assert (ungetc_char < 2); - //assert (ungetc_char == -1 || ungetc_char < 2); - //FIXME - //ungetc_buf[++ungetc_char] = c; - ungetc_char++; - ungetc_buf[ungetc_char] = c; - return c; + return fdungetc (c, (int)stream); } int @@ -356,7 +172,6 @@ fwrite (void const *data, size_t size, size_t count, FILE *stream) return 0; int bytes = write ((int)stream, data, size * count); if (bytes > 0) - //return bytes/size; return count; return bytes; } @@ -479,5 +294,3 @@ wait (int *status_ptr) { return waitpid (-1, status_ptr, 0); } - -#endif //!POSIX diff --git a/lib/libmes.c b/lib/libmes.c new file mode 100644 index 00000000..9f09b6f3 --- /dev/null +++ b/lib/libmes.c @@ -0,0 +1,199 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of Mes. + * + * 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. + * + * 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 Mes. If not, see . + */ + +#include + +int +isdigit (int c) +{ + return c >= '0' && c <= '9'; +} + +int +isxdigit (int c) +{ + return isdigit (c) || c >= 'a' && c <= 'f'; +} + +int +isspace (int c) +{ + return (c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r' || c == ' '); +} + +int +isnumber (int c, int base) +{ + if (base == 2) + return (c >= '0') && (c <= '1'); + if (base == 8) + return (c >= '0') && (c <= '7'); + if (base == 10) + return isdigit (c); + if (base == 16) + return isxdigit (c); +} + +int +abtoi (char const **p, int base) +{ + char const *s = *p; + int i = 0; + int sign = 1; + if (!base) base = 10; + if (*s && *s == '-') + { + sign = -1; + s++; + } + while (isnumber (*s, base)) + { + i *= base; + int m = *s > '9' ? 'a' - 10 : '0'; + i += *s - m; + s++; + } + *p = s; + return i * sign; +} + +int +atoi (char const *s) +{ + char const *p = s; + return abtoi (&p, 0); +} + +char const* +itoa (int x) +{ + static char itoa_buf[12]; + char *p = itoa_buf + 11; + *p-- = 0; + + int sign = 0; + unsigned u = x; + if (x < 0) + { + sign = 1; + u = -x; + } + + do + { + *p-- = '0' + (u % 10); + u = u / 10; + } while (u); + + if (sign && *(p + 1) != '0') + *p-- = '-'; + + return p+1; +} + +char const* +itoab (int x, int base) +{ + static char itoa_buf[12]; + char *p = itoa_buf + 11; + *p-- = 0; + + int sign = 0; + unsigned u = x; + if (x < 0) + { + sign = 1; + u = -x; + } + + do + { + int i = u % base; + *p-- = i > 9 ? 'a' + i - 10 : '0' + i; + x = u / base; + } while (u); + + if (sign && *(p + 1) != '0') + *p-- = '-'; + + return p+1; +} + +int _ungetc_pos = -1; +char _ungetc_buf[10]; + +int +fdgetc (int fd) +{ + char c; + int i; + if (_ungetc_pos == -1) + { + int r = read (fd, &c, 1); + if (r < 1) + return -1; + i = c; + } + else + { + i = _ungetc_buf[_ungetc_pos]; + _ungetc_pos -= 1; + } + if (i < 0) + i += 256; + + return i; +} + +int +fdputc (int c, int fd) +{ + write (fd, (char*)&c, 1); + return 0; +} + +int +putchar (int c) +{ + write (STDOUT, (char*)&c, 1); + return 0; +} + +int +fdputs (char const* s, int fd) +{ + int i = strlen (s); + write (fd, s, i); + return 0; +} + +int +fdungetc (int c, int fd) +{ + _ungetc_pos++; + _ungetc_buf[_ungetc_pos] = c; + return c; +} + +int +getchar () +{ + return fdgetc (g_stdin); +} diff --git a/lib/linux-gcc.c b/lib/linux-gcc.c index 3dfbf623..9294cb02 100644 --- a/lib/linux-gcc.c +++ b/lib/linux-gcc.c @@ -19,13 +19,11 @@ */ #include -#include +#include #include #include #include -#if !POSIX - int fork () { @@ -253,5 +251,3 @@ fsync (int fd) return r; #endif } - -#endif //!POSIX diff --git a/lib/linux-mini-gcc.c b/lib/linux-mini-gcc.c index e6914b3a..01ce07b3 100644 --- a/lib/linux-mini-gcc.c +++ b/lib/linux-mini-gcc.c @@ -18,8 +18,6 @@ * along with Mes. If not, see . */ -#if !POSIX - void exit (int code) { @@ -79,5 +77,3 @@ write (int fd, char const* s, int n) #endif return r; } - -#endif //!POSIX diff --git a/lib/m4.c b/lib/m4.c index af2343e6..a746a3ae 100644 --- a/lib/m4.c +++ b/lib/m4.c @@ -65,13 +65,6 @@ fileno (FILE *stream) return (int)stream; } -// void -// __fpurge (FILE *stream) -// { -// eputs ("__fpurge stub\n"); -// return 0; -// } - int fpurge (FILE *stream) { @@ -79,13 +72,6 @@ fpurge (FILE *stream) return 0; } -// size_t -// __freadahead (FILE *fp) -// { -// eputs ("__freadahead stub\n"); -// return 0; -// } - size_t freadahead (FILE *fp) { @@ -93,12 +79,6 @@ freadahead (FILE *fp) return 0; } -int -getc (FILE *stream) -{ - return fgetc ((int)stream); -} - int index (char const *s, int c) { @@ -222,3 +202,10 @@ tolower (int x) eputs ("tolower stub\n"); return 0; } + +int +toupper (int x) +{ + eputs ("toupper stub\n"); + return 0; +} diff --git a/scaffold/cons-mes.c b/scaffold/cons-mes.c index 1c89cf9a..b88ae1ae 100644 --- a/scaffold/cons-mes.c +++ b/scaffold/cons-mes.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include char arena[2000]; diff --git a/scaffold/malloc.c b/scaffold/malloc.c index df13c289..2c71e9a8 100644 --- a/scaffold/malloc.c +++ b/scaffold/malloc.c @@ -22,7 +22,7 @@ #error "POSIX not supported" #endif -#include +#include int main (int argc, char *argv[]) diff --git a/scaffold/mini-mes.c b/scaffold/mini-mes.c index 1a9e2abf..58df2d72 100644 --- a/scaffold/mini-mes.c +++ b/scaffold/mini-mes.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include int ARENA_SIZE = 200000; // 32b: 2MiB, 64b: 4 MiB int MAX_ARENA_SIZE = 300000000; diff --git a/scaffold/tests/52-itoa.c b/scaffold/tests/52-itoa.c index e2630038..ecf162fc 100644 --- a/scaffold/tests/52-itoa.c +++ b/scaffold/tests/52-itoa.c @@ -19,7 +19,7 @@ */ #include "30-test.i" -#include +#include #include #include diff --git a/scaffold/tests/61-array.c b/scaffold/tests/61-array.c index 25850c5a..84c0530d 100644 --- a/scaffold/tests/61-array.c +++ b/scaffold/tests/61-array.c @@ -18,7 +18,7 @@ * along with Mes. If not, see . */ -#include +#include #include #include diff --git a/scaffold/tests/79-int-array.c b/scaffold/tests/79-int-array.c index 00cc18bc..3619e4fd 100644 --- a/scaffold/tests/79-int-array.c +++ b/scaffold/tests/79-int-array.c @@ -20,7 +20,7 @@ #include "30-test.i" -#include +#include #include #include diff --git a/scaffold/tests/7c-dynarray.c b/scaffold/tests/7c-dynarray.c index 1a75c86f..61270f16 100644 --- a/scaffold/tests/7c-dynarray.c +++ b/scaffold/tests/7c-dynarray.c @@ -20,7 +20,7 @@ #include "30-test.i" -#include +#include #include #include #include diff --git a/scaffold/tests/7f-struct-pointer-arithmetic.c b/scaffold/tests/7f-struct-pointer-arithmetic.c index 140e7d96..eda2556b 100644 --- a/scaffold/tests/7f-struct-pointer-arithmetic.c +++ b/scaffold/tests/7f-struct-pointer-arithmetic.c @@ -20,7 +20,7 @@ #include "30-test.i" -#include +#include #include struct foo; diff --git a/scaffold/tests/7j-strtoull.c b/scaffold/tests/7j-strtoull.c index db78a9a4..27802ed2 100644 --- a/scaffold/tests/7j-strtoull.c +++ b/scaffold/tests/7j-strtoull.c @@ -19,7 +19,7 @@ */ #include "30-test.i" -#include +#include #include #include #include diff --git a/scaffold/tests/7n-struct-struct-array.c b/scaffold/tests/7n-struct-struct-array.c index 50e88143..eb5a11cc 100644 --- a/scaffold/tests/7n-struct-struct-array.c +++ b/scaffold/tests/7n-struct-struct-array.c @@ -20,7 +20,7 @@ #include "30-test.i" -#include +#include #include #include #include diff --git a/scaffold/tiny-mes.c b/scaffold/tiny-mes.c index 54c6b127..f21a728a 100644 --- a/scaffold/tiny-mes.c +++ b/scaffold/tiny-mes.c @@ -23,7 +23,7 @@ #endif #include -#include +#include char arena[300]; diff --git a/src/lib.c b/src/lib.c index 1dbbbf53..daf5f509 100644 --- a/src/lib.c +++ b/src/lib.c @@ -24,94 +24,94 @@ SCM fdisplay_ (SCM, int, int); SCM display_helper (SCM x, int cont, char* sep, int fd, int write_p) { - fputs (sep, fd); + fdputs (sep, fd); if (g_depth == 0) return cell_unspecified; g_depth = g_depth - 1; - + switch (TYPE (x)) { case TCHAR: { if (!write_p) - fputc (VALUE (x), fd); + fdputc (VALUE (x), fd); else { - fputs ("#\\", fd); + fdputs ("#\\", fd); switch (VALUE (x)) { - case '\0': fputs ("nul", fd); break; - case '\a': fputs ("alarm", fd); break; - case '\b': fputs ("backspace", fd); break; - case '\t': fputs ("tab", fd); break; - case '\n': fputs ("newline", fd); break; - case '\v': fputs ("vtab", fd); break; - case '\f': fputs ("page", fd); break; + case '\0': fdputs ("nul", fd); break; + case '\a': fdputs ("alarm", fd); break; + case '\b': fdputs ("backspace", fd); break; + case '\t': fdputs ("tab", fd); break; + case '\n': fdputs ("newline", fd); break; + case '\v': fdputs ("vtab", fd); break; + case '\f': fdputs ("page", fd); break; //Nyacc bug - // case '\r': fputs ("return", fd); break; - case 13: fputs ("return", fd); break; - case ' ': fputs ("space", fd); break; - default: fputc (VALUE (x), fd); + // case '\r': fdputs ("return", fd); break; + case 13: fdputs ("return", fd); break; + case ' ': fdputs ("space", fd); break; + default: fdputc (VALUE (x), fd); } } break; } case TCLOSURE: { - fputs ("#", fd); + fdputs (">", fd); break; } case TFUNCTION: { - fputs ("#", fd); + fdputs (p, fd); + fdputs ("[", fd); + fdputs (itoa (CDR (x)), fd); + fdputs (",", fd); + fdputs (itoa (x), fd); + fdputs ("]>", fd); break; } case TMACRO: { - fputs ("#", fd); + fdputs (">", fd); break; } case TVARIABLE: { - fputs ("#", fd); + fdputs (">", fd); break; } case TNUMBER: { - fputs (itoa (VALUE (x)), fd); + fdputs (itoa (VALUE (x)), fd); break; } case TPAIR: { if (!cont) - fputs ("(", fd); + fdputs ("(", fd); if (CAR (x) == cell_circular && CADR (x) != cell_closure) { - fputs ("(*circ* . ", fd); + fdputs ("(*circ* . ", fd); int i = 0; x = CDR (x); while (x != cell_nil && i++ < 10) { - fdisplay_ (CAAR (x), fd, write_p); fputs (" ", fd); + fdisplay_ (CAAR (x), fd, write_p); fdputs (" ", fd); x = CDR (x); } - fputs (" ...)", fd); + fdputs (" ...)", fd); } else { @@ -122,12 +122,12 @@ display_helper (SCM x, int cont, char* sep, int fd, int write_p) else if (CDR (x) && CDR (x) != cell_nil) { if (TYPE (CDR (x)) != TPAIR) - fputs (" . ", fd); + fdputs (" . ", fd); fdisplay_ (CDR (x), fd, write_p); } } if (!cont) - fputs (")", fd); + fdputs (")", fd); break; } case TKEYWORD: @@ -138,68 +138,68 @@ display_helper (SCM x, int cont, char* sep, int fd, int write_p) { if (TYPE (x) == TPORT) { - fputs ("#", fd); + fdputs (">", fd); break; } case TVECTOR: { - fputs ("#(", fd); + fdputs ("#(", fd); SCM t = CAR (x); for (int i = 0; i < LENGTH (x); i++) { if (i) - fputc (' ', fd); + fdputc (' ', fd); fdisplay_ (VECTOR (x) + i, fd, write_p); } - fputc (')', fd); + fdputc (')', fd); break; } default: { - fputs ("<", fd); - fputs (itoa (TYPE (x)), fd); - fputs (":", fd); - fputs (itoa (x), fd); - fputs (">", fd); + fdputs ("<", fd); + fdputs (itoa (TYPE (x)), fd); + fdputs (":", fd); + fdputs (itoa (x), fd); + fdputs (">", fd); break; } } diff --git a/src/mes.c b/src/mes.c index 13dcaa2d..f2c1e945 100644 --- a/src/mes.c +++ b/src/mes.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include //#define MES_MINI 1 #if _POSIX_SOURCE @@ -2196,18 +2196,18 @@ a = acons (lookup_symbol_ (scm_display_error_.string), cell_display_error_, a); if (g_debug > 3) { - fputs ("functions: ", STDERR); - fputs (itoa (g_function), STDERR); - fputs ("\n", STDERR); + fdputs ("functions: ", STDERR); + fdputs (itoa (g_function), STDERR); + fdputs ("\n", STDERR); for (int i = 0; i < g_function; i++) { - fputs ("[", STDERR); - fputs (itoa (i), STDERR); - fputs ("]: ", STDERR); - fputs (g_functions[i].name, STDERR); - fputs ("\n", STDERR); + fdputs ("[", STDERR); + fdputs (itoa (i), STDERR); + fdputs ("]: ", STDERR); + fdputs (g_functions[i].name, STDERR); + fdputs ("\n", STDERR); } - fputs ("\n", STDERR); + fdputs ("\n", STDERR); } return a; diff --git a/src/posix.c b/src/posix.c index 332c5807..b8dbf601 100644 --- a/src/posix.c +++ b/src/posix.c @@ -44,7 +44,7 @@ int readchar () { if (g_stdin >= 0) - return getchar (); + return fdgetc (g_stdin); SCM port = current_input_port (); SCM string = STRING (port); if (string == cell_nil) @@ -58,7 +58,7 @@ int unreadchar (int c) { if (g_stdin >= 0) - return ungetc (c, g_stdin); + return fdungetc (c, g_stdin); SCM port = current_input_port (); STRING (port) = cons (MAKE_CHAR (c), STRING (port)); return c;