From c33d6d00bc588a67f4d39e945709155df5ce2d37 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 18 May 2019 13:27:42 +0200 Subject: [PATCH] mes: Run build-aux/indent.sh. * src/mes.c: Re-indent. * src: Likewise. * include: Likewise. * lib: Likewise. * scaffold: Likewise. --- include/alloca.h | 6 +- include/ar.h | 22 +- include/assert.h | 2 +- include/dirent.h | 22 +- include/dirstream.h | 16 +- include/features.h | 1 - include/libgen.h | 2 +- include/locale.h | 2 +- include/math.h | 4 +- include/mes/lib-mini.h | 8 +- include/mes/lib.h | 4 +- include/pwd.h | 6 +- include/signal.h | 26 +- include/stdarg.h | 4 +- include/stdio.h | 54 +- include/stdlib.h | 12 +- include/string.h | 14 +- include/strings.h | 1 - include/sys/cdefs.h | 1 - include/sys/ioctl.h | 1 - include/sys/select.h | 3 +- include/sys/timeb.h | 1 - include/sys/ucontext.h | 1 - include/sys/user.h | 6 +- include/time.h | 5 +- include/unistd.h | 4 +- lib/assert/assert.c | 2 +- lib/dirent/__getdirentries.c | 2 +- lib/dirent/closedir.c | 2 +- lib/dirent/opendir.c | 4 +- lib/dirent/readdir.c | 41 +- lib/libmes.c | 2 +- lib/libtcc1.c | 6 +- lib/linux/access.c | 2 +- lib/linux/brk.c | 2 +- lib/linux/chdir.c | 2 +- lib/linux/chmod.c | 2 +- lib/linux/clock_gettime.c | 2 +- lib/linux/close.c | 2 +- lib/linux/dup.c | 2 +- lib/linux/dup2.c | 2 +- lib/linux/execve.c | 4 +- lib/linux/fcntl.c | 2 +- lib/linux/fstat.c | 2 +- lib/linux/fsync.c | 2 +- lib/linux/getcwd.c | 2 +- lib/linux/getdents.c | 2 +- lib/linux/getrusage.c | 2 +- lib/linux/gettimeofday.c | 2 +- lib/linux/ioctl.c | 2 +- lib/linux/kill.c | 2 +- lib/linux/link.c | 2 +- lib/linux/lseek.c | 2 +- lib/linux/lstat.c | 2 +- lib/linux/mkdir.c | 2 +- lib/linux/nanosleep.c | 5 +- lib/linux/open.c | 2 +- lib/linux/pipe.c | 2 +- lib/linux/read.c | 15 +- lib/linux/rename.c | 2 +- lib/linux/rmdir.c | 2 +- lib/linux/setgid.c | 2 +- lib/linux/settimer.c | 5 +- lib/linux/setuid.c | 2 +- lib/linux/signal.c | 4 +- lib/linux/sigprogmask.c | 6 +- lib/linux/stat.c | 2 +- lib/linux/time.c | 4 +- lib/linux/unlink.c | 2 +- lib/linux/waitpid.c | 4 +- lib/linux/x86_64-mes/crt1.c | 10 +- lib/linux/x86_64-mes/mes.c | 2 +- lib/linux/x86_64-mes/mini.c | 4 +- lib/mes/eputs.c | 2 +- lib/mes/fdgetc.c | 6 +- lib/mes/fdputc.c | 2 +- lib/mes/fdputs.c | 2 +- lib/mes/ntoab.c | 13 +- lib/mes/oputs.c | 2 +- lib/mes/search-path.c | 12 +- lib/posix/execl.c | 12 +- lib/posix/execvp.c | 10 +- lib/posix/getenv.c | 2 +- lib/posix/getopt.c | 319 ++++----- lib/posix/mktemp.c | 14 +- lib/posix/setenv.c | 2 +- lib/posix/wait.c | 2 +- lib/stdio/clearerr.c | 2 +- lib/stdio/fclose.c | 4 +- lib/stdio/fdopen.c | 2 +- lib/stdio/feof.c | 2 +- lib/stdio/ferror.c | 4 +- lib/stdio/fflush.c | 4 +- lib/stdio/fgetc.c | 4 +- lib/stdio/fgets.c | 4 +- lib/stdio/fileno.c | 4 +- lib/stdio/fopen.c | 18 +- lib/stdio/fprintf.c | 2 +- lib/stdio/fputc.c | 4 +- lib/stdio/fputs.c | 4 +- lib/stdio/fread.c | 25 +- lib/stdio/freeopen.c | 2 +- lib/stdio/freopen.c | 2 +- lib/stdio/fseek.c | 11 +- lib/stdio/ftell.c | 4 +- lib/stdio/fwrite.c | 19 +- lib/stdio/getc.c | 4 +- lib/stdio/printf.c | 2 +- lib/stdio/putc.c | 4 +- lib/stdio/putchar.c | 2 +- lib/stdio/snprintf.c | 2 +- lib/stdio/sprintf.c | 2 +- lib/stdio/ungetc.c | 4 +- lib/stdio/vfprintf.c | 8 +- lib/stdio/vprintf.c | 2 +- lib/stdio/vsnprintf.c | 6 +- lib/stdio/vsprintf.c | 2 +- lib/stdio/vsscanf.c | 4 +- lib/stdlib/alloca.c | 39 +- lib/stdlib/mbstowcs.c | 3 +- lib/stdlib/puts.c | 2 +- lib/stdlib/qsort.c | 30 +- lib/string/argz-count.c | 6 +- lib/string/argz-extract.c | 1 + lib/string/memcpy.c | 4 +- lib/string/memmem.c | 10 +- lib/string/memmove.c | 2 +- lib/string/strcmp.c | 2 +- lib/string/strdup.c | 2 +- lib/string/strerror.c | 89 +-- lib/string/strlen.c | 2 +- lib/string/strncat.c | 2 +- lib/string/strncmp.c | 2 +- lib/string/strpbrk.c | 2 +- lib/stub/fpurge.c | 2 +- lib/stub/freadahead.c | 2 +- lib/stub/setvbuf.c | 2 +- lib/stub/sigaddset.c | 2 +- lib/stub/sigdelset.c | 2 +- lib/stub/sigemptyset.c | 2 +- lib/stub/strftime.c | 3 +- lib/stub/ttyname.c | 2 +- lib/tests/assert/50-assert.c | 2 +- lib/tests/dirent/90-readdir.c | 11 +- lib/tests/io/90-stat.c | 84 ++- lib/tests/mes/50-itoa.c | 4 +- lib/tests/setjmp/80-setjmp.c | 14 +- lib/tests/signal/90-signal.c | 14 +- lib/tests/stdio/70-printf-simple.c | 13 +- lib/tests/stdio/70-printf.c | 58 +- lib/tests/stdio/90-fopen-append.c | 45 +- lib/tests/stdio/90-fopen.c | 24 +- lib/tests/stdio/90-fread-fwrite.c | 6 +- lib/tests/stdio/90-fseek.c | 9 +- lib/tests/stdlib/50-malloc.c | 4 +- lib/tests/stdlib/70-strtoull.c | 14 +- lib/tests/stdlib/80-qsort-dupes.c | 11 +- lib/tests/stdlib/80-qsort.c | 24 +- lib/tests/stdlib/90-strtol.c | 12 +- lib/tests/string/30-strlen.c | 2 +- lib/tests/string/50-strcmp.c | 10 +- lib/tests/string/80-strncpy.c | 2 +- lib/tests/string/90-snprintf.c | 6 +- lib/tests/string/90-strpbrk.c | 8 +- lib/x86-mes-gcc/setjmp.c | 4 +- lib/x86-mes/setjmp.c | 14 +- lib/x86_64-mes/setjmp.c | 16 +- scaffold/argv.c | 2 +- scaffold/cons-mes.c | 417 +++++++---- scaffold/micro-mes.c | 12 +- scaffold/read.c | 9 +- scaffold/tests/14-if-goto.c | 4 +- scaffold/tests/17-compare-unsigned-char-le.c | 2 +- scaffold/tests/17-compare-unsigned-short-le.c | 2 +- scaffold/tests/18-assign-shadow.c | 4 +- scaffold/tests/32-call-wrap.c | 2 +- scaffold/tests/32-compare.c | 27 +- scaffold/tests/33-and-or.c | 6 +- scaffold/tests/34-pre-post.c | 4 +- scaffold/tests/35-compare-char.c | 10 +- scaffold/tests/38-compare-call.c | 8 +- scaffold/tests/42-goto-label.c | 2 +- scaffold/tests/43-for-do-while.c | 14 +- scaffold/tests/44-switch-body-fallthrough.c | 17 +- scaffold/tests/44-switch-fallthrough.c | 17 +- scaffold/tests/44-switch.c | 11 +- scaffold/tests/47-function-expression.c | 2 +- scaffold/tests/48-global-static.c | 4 +- scaffold/tests/51-pointer-sub.c | 4 +- scaffold/tests/54-argc.c | 4 +- scaffold/tests/54-argv.c | 4 +- scaffold/tests/55-char-array.c | 26 +- scaffold/tests/60-math.c | 18 +- scaffold/tests/61-array.c | 36 +- scaffold/tests/62-array.c | 28 +- scaffold/tests/63-struct-array-assign.c | 2 +- scaffold/tests/63-struct-array-compare.c | 4 +- scaffold/tests/63-struct-array.c | 2 +- scaffold/tests/63-struct-assign.c | 4 +- scaffold/tests/63-struct-cell.c | 42 +- scaffold/tests/63-struct-function.c | 3 +- scaffold/tests/63-struct-local.c | 2 +- scaffold/tests/63-struct-pointer.c | 3 +- scaffold/tests/63-struct.c | 2 +- scaffold/tests/64-make-cell.c | 70 +- scaffold/tests/65-read.c | 4 +- scaffold/tests/66-local-char-array.c | 38 +- scaffold/tests/70-stdarg.c | 18 +- scaffold/tests/71-struct-array.c | 10 +- scaffold/tests/72-typedef-struct-def.c | 33 +- scaffold/tests/73-union-hello.c | 2 +- scaffold/tests/73-union.c | 8 +- scaffold/tests/74-multi-line-string.c | 8 +- scaffold/tests/75-struct-union.c | 24 +- scaffold/tests/76-pointer-arithmetic.c | 89 ++- scaffold/tests/77-pointer-assign.c | 51 +- scaffold/tests/78-union-struct.c | 13 +- scaffold/tests/79-int-array-simple.c | 4 +- scaffold/tests/79-int-array.c | 38 +- scaffold/tests/7a-struct-char-array.c | 18 +- scaffold/tests/7b-struct-int-array-hello.c | 2 +- scaffold/tests/7b-struct-int-array-pointer.c | 2 +- scaffold/tests/7b-struct-int-array.c | 9 +- scaffold/tests/7c-dynarray.c | 136 ++-- scaffold/tests/7d-cast-char.c | 16 +- scaffold/tests/7e-struct-array-access.c | 36 +- scaffold/tests/7f-struct-pointer-arithmetic.c | 52 +- scaffold/tests/7g-struct-byte-word-field.c | 33 +- scaffold/tests/7h-struct-assign.c | 127 ++-- scaffold/tests/7i-struct-struct-simple.c | 2 +- scaffold/tests/7i-struct-struct.c | 23 +- scaffold/tests/7k-empty-for.c | 2 +- scaffold/tests/7k-for-each-elem-simple.c | 7 +- scaffold/tests/7k-for-each-elem.c | 46 +- scaffold/tests/7l-struct-any-size-array.c | 10 +- scaffold/tests/7m-struct-char-array-assign.c | 6 +- scaffold/tests/7n-struct-struct-array.c | 54 +- scaffold/tests/7o-struct-pre-post-simple.c | 17 +- scaffold/tests/7o-struct-pre-post.c | 22 +- scaffold/tests/7p-struct-cast.c | 14 +- scaffold/tests/7q-bit-field-simple.c | 6 +- scaffold/tests/7q-bit-field.c | 6 +- scaffold/tests/7r-sign-extend.c | 13 +- scaffold/tests/7s-struct-short.c | 9 +- scaffold/tests/7t-function-destruct.c | 6 +- scaffold/tests/7u-struct-func.c | 4 +- scaffold/tests/7u-struct-size10.c | 10 +- scaffold/tests/7u-vstack.c | 3 +- scaffold/tests/82-define.c | 6 +- scaffold/tests/83-heterogenoous-init.c | 2 +- scaffold/tests/84-struct-field-list.c | 4 +- scaffold/tests/85-sizeof.c | 4 +- scaffold/tests/90-goto-var.c | 2 +- scaffold/tests/91-goto-array.c | 38 +- scaffold/tests/a0-call-trunc-char.c | 6 +- scaffold/tests/a0-call-trunc-int.c | 8 +- scaffold/tests/a0-call-trunc-short.c | 6 +- scaffold/tests/t.c | 107 ++- scaffold/tiny-mes.c | 160 +++-- src/gc.c | 86 ++- src/hash.c | 21 +- src/lib.c | 155 ++-- src/math.c | 22 +- src/mes.c | 661 +++++++++--------- src/module.c | 18 +- src/posix.c | 49 +- src/reader.c | 128 ++-- src/string.c | 53 +- src/struct.c | 8 +- src/vector.c | 8 +- 270 files changed, 2900 insertions(+), 2110 deletions(-) diff --git a/include/alloca.h b/include/alloca.h index eae15876..71c9b483 100644 --- a/include/alloca.h +++ b/include/alloca.h @@ -36,11 +36,11 @@ typedef unsigned long size_t; #endif #if _ALLOCA_UNSIGNED -void * alloca (unsigned size); +void *alloca (unsigned size); #elif _ALLOCA_CHAR -char * alloca (int); +char *alloca (int); #else -void * alloca (size_t size); +void *alloca (size_t size); #endif #endif // ! WITH_GLIBC diff --git a/include/ar.h b/include/ar.h index bcefb3d0..ab01cb8f 100644 --- a/include/ar.h +++ b/include/ar.h @@ -36,20 +36,20 @@ `struct ar_hdr', and as many bytes of member file data as its `ar_size' member indicates, for each member file. */ -#define ARMAG "!\n" /* String that begins an archive file. */ -#define SARMAG 8 /* Size of that string. */ +#define ARMAG "!\n" /* String that begins an archive file. */ +#define SARMAG 8 /* Size of that string. */ -#define ARFMAG "`\n" /* String in ar_fmag at end of each header. */ +#define ARFMAG "`\n" /* String in ar_fmag at end of each header. */ struct ar_hdr - { - char ar_name[16]; /* Member file name, sometimes / terminated. */ - char ar_date[12]; /* File date, decimal seconds since Epoch. */ - char ar_uid[6], ar_gid[6]; /* User and group IDs, in ASCII decimal. */ - char ar_mode[8]; /* File mode, in ASCII octal. */ - char ar_size[10]; /* File size, in ASCII decimal. */ - char ar_fmag[2]; /* Always contains ARFMAG. */ - }; +{ + char ar_name[16]; /* Member file name, sometimes / terminated. */ + char ar_date[12]; /* File date, decimal seconds since Epoch. */ + char ar_uid[6], ar_gid[6]; /* User and group IDs, in ASCII decimal. */ + char ar_mode[8]; /* File mode, in ASCII octal. */ + char ar_size[10]; /* File size, in ASCII decimal. */ + char ar_fmag[2]; /* Always contains ARFMAG. */ +}; #endif // ! WITH_GLIBC diff --git a/include/assert.h b/include/assert.h index 7bfbac48..11f63139 100644 --- a/include/assert.h +++ b/include/assert.h @@ -28,7 +28,7 @@ #include_next #else // ! WITH_GLIBC #define assert(x) ((x) ? (void)0 : assert_fail (#x)) -void assert_fail (char* s); +void assert_fail (char *s); #endif // ! WITH_GLIBC #endif // __MES_ASSERT_H diff --git a/include/dirent.h b/include/dirent.h index cc8be20b..fb45229a 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -41,18 +41,18 @@ #include -int __getdirentries (int filedes, char *buffer, size_t nbytes, off_t *basep); +int __getdirentries (int filedes, char *buffer, size_t nbytes, off_t * basep); struct dirent - { - ino_t d_ino; - off_t d_off; - unsigned short int d_reclen; +{ + ino_t d_ino; + off_t d_off; + unsigned short int d_reclen; #if 0 - unsigned char d_type; + unsigned char d_type; #endif - char d_name[256]; /* We must not include limits.h! */ - }; + char d_name[256]; /* We must not include limits.h! */ +}; /* Open a directory stream on NAME. Return a DIR stream on the directory, or NULL if it could not be opened. */ @@ -60,16 +60,16 @@ DIR *opendir (char const *name); /* Close the directory stream DIRP. Return 0 if successful, -1 if not. */ -int closedir (DIR *dirp); +int closedir (DIR * dirp); /* Read a directory entry from DIRP. Return a pointer to a `struct dirent' describing the entry, or NULL for EOF or error. The storage returned may be overwritten by a later readdir call on the same DIR stream. */ -struct dirent *readdir (DIR *dirp); +struct dirent *readdir (DIR * dirp); /* Rewind DIRP to the beginning of the directory. */ -extern void rewinddir (DIR *dirp); +extern void rewinddir (DIR * dirp); #endif // ! WITH_GLIBC diff --git a/include/dirstream.h b/include/dirstream.h index d4c43437..31e369b1 100644 --- a/include/dirstream.h +++ b/include/dirstream.h @@ -37,16 +37,16 @@ /* Directory stream type. */ struct __dirstream - { - int fd; /* File descriptor. */ +{ + int fd; /* File descriptor. */ - char *data; /* Directory block. */ - size_t allocation; /* Space allocated for the block. */ - size_t size; /* Total valid data in the block. */ - size_t offset; /* Current offset into the block. */ + char *data; /* Directory block. */ + size_t allocation; /* Space allocated for the block. */ + size_t size; /* Total valid data in the block. */ + size_t offset; /* Current offset into the block. */ - off_t filepos; /* Position of next entry to read. */ - }; + off_t filepos; /* Position of next entry to read. */ +}; typedef struct __dirstream DIR; diff --git a/include/features.h b/include/features.h index 1d0e7eb7..aa56b052 100644 --- a/include/features.h +++ b/include/features.h @@ -26,4 +26,3 @@ #endif // (WITH_GLIBC) #endif // __MES_FEATURES_H - diff --git a/include/libgen.h b/include/libgen.h index 2cb080c4..be76015c 100644 --- a/include/libgen.h +++ b/include/libgen.h @@ -28,7 +28,7 @@ #include_next #else // ! WITH_GLIBC -char* dirname (char*); +char *dirname (char *); #endif // ! WITH_GLIBC #endif // __MES_LIBGEN_H diff --git a/include/locale.h b/include/locale.h index 12b145a0..1cdacda6 100644 --- a/include/locale.h +++ b/include/locale.h @@ -38,7 +38,7 @@ #endif // *INDENT-ON* -char * setlocale (int category, char const *locale); +char *setlocale (int category, char const *locale); #endif // ! WITH_GLIBC diff --git a/include/math.h b/include/math.h index aea4e923..6ba64bcf 100644 --- a/include/math.h +++ b/include/math.h @@ -23,9 +23,9 @@ #if WITH_GLIBC #undef __MES_MATH_H #include_next -#else // ! WITH_GLIBC +#else // ! WITH_GLIBC double ldexp (double x, int exp); -#endif // ! WITH_GLIBC +#endif // ! WITH_GLIBC double fabs (double number); diff --git a/include/mes/lib-mini.h b/include/mes/lib-mini.h index ed141a92..7bc49534 100644 --- a/include/mes/lib-mini.h +++ b/include/mes/lib-mini.h @@ -79,12 +79,12 @@ int __stdin; int __stdout; int __stderr; -int eputs (char const* s); -int puts (char const* s); -int oputs (char const* s); +int eputs (char const *s); +int puts (char const *s); +int oputs (char const *s); #if !WITH_GLIBC -size_t strlen (char const* s); +size_t strlen (char const *s); ssize_t _write (); ssize_t write (int filedes, void const *buffer, size_t size); #endif // !WITH_GLIBC diff --git a/include/mes/lib.h b/include/mes/lib.h index 91b39783..3e74c2dd 100644 --- a/include/mes/lib.h +++ b/include/mes/lib.h @@ -39,7 +39,7 @@ int atoi (char const *s); int eputc (int c); int fdgetc (int fd); int fdputc (int c, int fd); -int fdputs (char const* s, int fd); +int fdputs (char const *s, int fd); int fdungetc (int c, int fd); int _fdungetc_p (int fd); int isdigit (int c); @@ -49,7 +49,7 @@ int mes_open (char const *file_name, int flags, int mask); int _open2 (char const *file_name, int flags); int _open3 (char const *file_name, int flags, int mask); int oputc (int c); -int oputs (char const* s); +int oputs (char const *s); char *search_path (char const *file_name); #endif //__MES_LIB_H diff --git a/include/pwd.h b/include/pwd.h index f0ce9244..f519e8e5 100644 --- a/include/pwd.h +++ b/include/pwd.h @@ -23,7 +23,7 @@ #if WITH_GLIBC #undef __MES_PWD_H #include_next -#else // ! WITH_GLIBC +#else // ! WITH_GLIBC struct passwd { @@ -36,9 +36,9 @@ struct passwd char *pw_shell; }; -struct passwd * getpwuid (); +struct passwd *getpwuid (); -#endif // ! WITH_GLIBC +#endif // ! WITH_GLIBC #endif // __MES_PWD_H diff --git a/include/signal.h b/include/signal.h index db127752..b8ed5299 100644 --- a/include/signal.h +++ b/include/signal.h @@ -118,7 +118,7 @@ typedef struct siginfo_t #if __MESC__ typedef long sighandler_t; #else -typedef void (*sighandler_t)(int); +typedef void (*sighandler_t) (int); #endif struct sigaction @@ -199,14 +199,14 @@ struct _libc_fpstate typedef struct _libc_fpstate *fpregset_t; typedef struct - { - gregset_t gregs; - /* Due to Linux's history we have to use a pointer here. The SysV/i386 - ABI requires a struct with the values. */ - fpregset_t fpregs; - unsigned long int oldmask; - unsigned long int cr2; - } mcontext_t; +{ + gregset_t gregs; + /* Due to Linux's history we have to use a pointer here. The SysV/i386 + ABI requires a struct with the values. */ + fpregset_t fpregs; + unsigned long int oldmask; + unsigned long int cr2; +} mcontext_t; /* Userlevel context. */ typedef struct ucontext @@ -222,19 +222,19 @@ typedef struct ucontext int kill (pid_t pid, int signum); int sigaction (int signum, struct sigaction const *act, struct sigaction *oldact); -int sigaddset (sigset_t *set, int signum); +int sigaddset (sigset_t * set, int signum); #if __MESC__ -void* signal (int signum, void * action); +void *signal (int signum, void *action); #else sighandler_t signal (int signum, sighandler_t action); #endif -int sigemptyset (sigset_t *set); +int sigemptyset (sigset_t * set); #ifndef SIG_BLOCK #define SIG_BLOCK 0 #define SIG_UNBLOCK 1 #define SIG_SETMASK 2 #endif -int sigprocmask (int how, sigset_t const *set, sigset_t *oldset); +int sigprocmask (int how, sigset_t const *set, sigset_t * oldset); #endif //! WITH_GLIBC diff --git a/include/stdarg.h b/include/stdarg.h index 70912eb1..0c8c3f39 100644 --- a/include/stdarg.h +++ b/include/stdarg.h @@ -37,8 +37,8 @@ typedef char *va_list; #define va_end(ap) (void)((ap) = 0) #define va_copy(dest, src) dest = src -int vfprintf (FILE *stream, char const *template, va_list ap); -int vprintf (char const* format, va_list ap); +int vfprintf (FILE * stream, char const *template, va_list ap); +int vprintf (char const *format, va_list ap); int vsprintf (char *str, char const *format, va_list ap); int vsnprintf (char *str, size_t size, char const *format, va_list ap); int vsscanf (char const *s, char const *template, va_list ap); diff --git a/include/stdio.h b/include/stdio.h index b305fe46..cd8d8bd8 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -32,9 +32,9 @@ #else // ! WITH_GLIBC #ifndef _IOFBF -#define _IOFBF 0 /* Fully buffered. */ -#define _IOLBF 1 /* Line buffered. */ -#define _IONBF 2 /* No buffering. */ +#define _IOFBF 0 /* Fully buffered. */ +#define _IOLBF 1 /* Line buffered. */ +#define _IONBF 2 /* No buffering. */ #endif #ifndef BUFSIZ @@ -58,35 +58,35 @@ 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); -int feof (FILE *stream); -int ferror (FILE *stream); -int fflush (FILE *stream); -int fgetc (FILE* stream); -char *fgets (char *s, int size, FILE *stream); -int fprintf (FILE *stream, char const *format, ...); -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); -int getc (FILE *stream); +int eputs (char const *s); +int fclose (FILE * stream); +int feof (FILE * stream); +int ferror (FILE * stream); +int fflush (FILE * stream); +int fgetc (FILE * stream); +char *fgets (char *s, int size, FILE * stream); +int fprintf (FILE * stream, char const *format, ...); +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); +int getc (FILE * stream); int getchar (void); char *getlogin (void); -int printf (char const* format, ...); -int putc (int c, FILE* stream); +int printf (char const *format, ...); +int putc (int c, FILE * stream); int putchar (int c); -int puts (char const* s); +int puts (char const *s); int remove (char const *file_name); -int setvbuf (FILE *stream, char *buf, int mode, size_t size); -int snprintf(char *str, size_t size, char const *format, ...); -int sprintf (char *str, char const* format, ...); +int setvbuf (FILE * stream, char *buf, int mode, size_t size); +int snprintf (char *str, size_t size, char const *format, ...); +int sprintf (char *str, char const *format, ...); 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); +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 // ! WITH_GLIBC diff --git a/include/stdlib.h b/include/stdlib.h index ce0b1a94..7cc4e5c0 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -26,7 +26,7 @@ #endif #undef __MES_STDLIB_H #include_next -#else // ! WITH_GLIBC +#else // ! WITH_GLIBC #include #include @@ -34,15 +34,15 @@ double atof (char const *s); int atoi (char const *s); int atexit (void (*function) (void)); -void * calloc (size_t nmemb, size_t size); +void *calloc (size_t nmemb, size_t size); void _exit (int status); void exit (int status); void free (void *ptr); -char* getenv (char const* s); -int setenv (char const* s, char const* v, int overwrite_p); +char *getenv (char const *s); +int setenv (char const *s, char const *v, int overwrite_p); void unsetenv (char const *name); void *malloc (size_t); -void qsort (void *base, size_t nmemb, size_t size, int (*compar)(void const *, void const *)); +void qsort (void *base, size_t nmemb, size_t size, int (*compar) (void const *, void const *)); int rand (void); void *realloc (void *p, size_t size); double strtod (char const *string, char **tailptr); @@ -61,7 +61,7 @@ unsigned long long strtoull (char const *string, char **tailptr, int base); typedef int (*comparison_fn_t) (void const *, void const *); #endif -void * bsearch (void const *key, void const *array, size_t count, size_t size, comparison_fn_t compare); +void *bsearch (void const *key, void const *array, size_t count, size_t size, comparison_fn_t compare); #endif // ! WITH_GLIBC diff --git a/include/string.h b/include/string.h index eb3a6215..7b3056eb 100644 --- a/include/string.h +++ b/include/string.h @@ -45,25 +45,25 @@ typedef unsigned long size_t; typedef long ssize_t; #endif -void * memchr (void const *block, int c, size_t size); +void *memchr (void const *block, int c, size_t size); void *memcpy (void *dest, void const *src, size_t n); void *memmove (void *dest, void const *src, size_t n); void *memset (void *s, int c, size_t n); -void * memchr (void const *block, int c, size_t size); +void *memchr (void const *block, int c, size_t size); int memcmp (void const *s1, void const *s2, size_t n); char *strcat (char *dest, char const *src); char *strchr (char const *s, int c); int strcasecmp (char const *s1, char const *s2); -int strcmp (char const*, char const*); +int strcmp (char const *, char const *); char *strcpy (char *dest, char const *src); -size_t strlen (char const*); +size_t strlen (char const *); char *strncpy (char *to, char const *from, size_t size); -int strncmp (char const*, char const*, size_t); +int strncmp (char const *, char const *, size_t); char *strrchr (char const *s, int c); char *strstr (char const *haystack, char const *needle); -char * strlwr (char *string); -char * strupr (char *string); +char *strlwr (char *string); +char *strupr (char *string); char *strerror (int errnum); diff --git a/include/strings.h b/include/strings.h index 9f56b68f..87041dc6 100644 --- a/include/strings.h +++ b/include/strings.h @@ -26,4 +26,3 @@ #endif // (WITH_GLIBC) #endif // __MES_STRINGS_H - diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h index ffabc307..8efde99b 100644 --- a/include/sys/cdefs.h +++ b/include/sys/cdefs.h @@ -26,4 +26,3 @@ #endif // (WITH_GLIBC) #endif // __MES_SYS_CDEFS_H - diff --git a/include/sys/ioctl.h b/include/sys/ioctl.h index e1bff6af..dfe296a1 100644 --- a/include/sys/ioctl.h +++ b/include/sys/ioctl.h @@ -33,4 +33,3 @@ int ioctl (int fd, unsigned long request, ...); #endif // ! WITH_GLIBC #endif // __MES_SYS_IOCTL_H - diff --git a/include/sys/select.h b/include/sys/select.h index d82636fa..9dc160bd 100644 --- a/include/sys/select.h +++ b/include/sys/select.h @@ -23,9 +23,8 @@ #if WITH_GLIBC #undef __MES_SYS_SELECT_H #include_next -#else //! WITH_GLIBC +#else //! WITH_GLIBC typedef int fd_set; #endif //! WITH_GLIBC #endif // __MES_SYS_SELECT_H - diff --git a/include/sys/timeb.h b/include/sys/timeb.h index 259250a0..31e40ece 100644 --- a/include/sys/timeb.h +++ b/include/sys/timeb.h @@ -26,4 +26,3 @@ #endif // (WITH_GLIBC) #endif // __MES_SYS_TIMEB_H - diff --git a/include/sys/ucontext.h b/include/sys/ucontext.h index ba473db7..fa7df2bc 100644 --- a/include/sys/ucontext.h +++ b/include/sys/ucontext.h @@ -26,4 +26,3 @@ #endif // (WITH_GLIBC) #endif // __MES_SYS_UCONTEXT_H - diff --git a/include/sys/user.h b/include/sys/user.h index 99d29dd9..5f90fd58 100644 --- a/include/sys/user.h +++ b/include/sys/user.h @@ -36,7 +36,7 @@ struct user_fpregs_struct long int fcs; long int foo; long int fos; - long int st_space [20]; + long int st_space[20]; }; struct user_fpxregs_struct @@ -51,8 +51,8 @@ struct user_fpxregs_struct long int fos; long int mxcsr; long int reserved; - long int st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */ - long int xmm_space[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */ + long int st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */ + long int xmm_space[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */ long int padding[56]; }; diff --git a/include/time.h b/include/time.h index e60a49a4..b022f11b 100644 --- a/include/time.h +++ b/include/time.h @@ -31,7 +31,8 @@ typedef long int clockid_t; typedef long int time_t; #endif -struct tm { +struct tm +{ int tm_sec; int tm_min; int tm_hour; @@ -59,7 +60,7 @@ int clock_gettime (clockid_t clk_id, struct timespec *tp); struct tm *localtime (time_t const *timep); struct tm *gmtime (time_t const *time); -time_t time (time_t *tloc); +time_t time (time_t * tloc); #endif // ! WITH_GLIBC diff --git a/include/unistd.h b/include/unistd.h index 8810cbf4..d0bb2ef8 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -78,9 +78,9 @@ off_t lseek (int fd, off_t offset, int whence); ssize_t read (int fd, void *buffer, size_t size); #if __SBRK_CHAR_PTRDIFF /* xmalloc in binutils <= 2.10.1 uses this old prototype */ -char * sbrk (ptrdiff_t delta); +char *sbrk (ptrdiff_t delta); #else -void * sbrk (intptr_t delta); +void *sbrk (intptr_t delta); #endif int unlink (char const *file_name); ssize_t write (int filedes, void const *buffer, size_t size); diff --git a/lib/assert/assert.c b/lib/assert/assert.c index c72177bd..428410ba 100644 --- a/lib/assert/assert.c +++ b/lib/assert/assert.c @@ -1,5 +1,5 @@ void -assert_fail (char* s) +assert_fail (char *s) { eputs ("assert fail: "); eputs (s); diff --git a/lib/dirent/__getdirentries.c b/lib/dirent/__getdirentries.c index 923eedcc..46adb74d 100644 --- a/lib/dirent/__getdirentries.c +++ b/lib/dirent/__getdirentries.c @@ -26,7 +26,7 @@ #include int -__getdirentries (int filedes, char *buffer, size_t nbytes, off_t *basep) +__getdirentries (int filedes, char *buffer, size_t nbytes, off_t * basep) { if (basep) *basep = lseek (filedes, (off_t) 0, SEEK_CUR); diff --git a/lib/dirent/closedir.c b/lib/dirent/closedir.c index 743778ef..325e6920 100644 --- a/lib/dirent/closedir.c +++ b/lib/dirent/closedir.c @@ -37,7 +37,7 @@ /* Close the directory stream DIRP. Return 0 if successful, -1 if not. */ int -closedir (DIR *dirp) +closedir (DIR * dirp) { int filedes; diff --git a/lib/dirent/opendir.c b/lib/dirent/opendir.c index c0a75c58..25b77e3d 100644 --- a/lib/dirent/opendir.c +++ b/lib/dirent/opendir.c @@ -47,12 +47,12 @@ opendir (char const *name) if (name[0] == '\0') { /* POSIX.1-1990 says an empty name gets ENOENT; - but `open' might like it fine. */ + but `open' might like it fine. */ errno = ENOENT; return 0; } - fd = open (name, O_RDONLY|O_DIRECTORY); + fd = open (name, O_RDONLY | O_DIRECTORY); if (fd < 0) return 0; diff --git a/lib/dirent/readdir.c b/lib/dirent/readdir.c index b8783977..3f38d044 100644 --- a/lib/dirent/readdir.c +++ b/lib/dirent/readdir.c @@ -34,7 +34,7 @@ /* Read a directory entry from DIRP. */ struct dirent * -readdir (DIR *dirp) +readdir (DIR * dirp) { struct dirent *dp; int saved_errno = errno; @@ -44,33 +44,33 @@ readdir (DIR *dirp) size_t reclen; if (dirp->offset >= dirp->size) - { - /* We've emptied out our buffer. Refill it. */ + { + /* We've emptied out our buffer. Refill it. */ - size_t maxread; - ssize_t bytes; + size_t maxread; + ssize_t bytes; - maxread = dirp->allocation; + maxread = dirp->allocation; #if 0 - off_t base; - bytes = __getdirentries (dirp->fd, dirp->data, maxread, &base); + off_t base; + bytes = __getdirentries (dirp->fd, dirp->data, maxread, &base); #else bytes = getdents (dirp->fd, dirp->data, maxread); #endif - if (bytes <= 0) - { - /* Don't modifiy errno when reaching EOF. */ - if (bytes == 0) + if (bytes <= 0) + { + /* Don't modifiy errno when reaching EOF. */ + if (bytes == 0) errno = saved_errno; - dp = 0; - break; - } - dirp->size = (size_t) bytes; + dp = 0; + break; + } + dirp->size = (size_t) bytes; - /* Reset the offset into the buffer. */ - dirp->offset = 0; - } + /* Reset the offset into the buffer. */ + dirp->offset = 0; + } dp = (struct dirent *) &dirp->data[dirp->offset]; @@ -79,7 +79,8 @@ readdir (DIR *dirp) dirp->filepos = dp->d_off; /* Skip deleted files. */ - } while (dp->d_ino == 0); + } + while (dp->d_ino == 0); return dp; } diff --git a/lib/libmes.c b/lib/libmes.c index d7bdac91..528d1c45 100644 --- a/lib/libmes.c +++ b/lib/libmes.c @@ -57,7 +57,7 @@ mes_open (char const *file_name, int flags, int mask) if (r > 2) __ungetc_buf[r] = -1; return r; - } +} #include #include diff --git a/lib/libtcc1.c b/lib/libtcc1.c index 64e2ce4c..abdc701f 100644 --- a/lib/libtcc1.c +++ b/lib/libtcc1.c @@ -27,7 +27,7 @@ __divdi3 (double a, double b) if (__mes_debug () && !stub) eputs ("__divdi3 stub\n"); stub = 1; - return ((int)a / (int)b); + return ((int) a / (int) b); } double @@ -37,7 +37,7 @@ __moddi3 (double a, double b) if (__mes_debug () && !stub) eputs ("__moddi3 stub\n"); stub = 1; - return ((int) a %(int)b); + return ((int) a % (int) b); } unsigned long long @@ -120,7 +120,7 @@ long int #else // !__TINYCC_ long long -#endif // !__TINYCC_ +#endif // !__TINYCC_ __fixdfdi (double a1) { static int stub = 0; diff --git a/lib/linux/access.c b/lib/linux/access.c index 22907808..e064f460 100644 --- a/lib/linux/access.c +++ b/lib/linux/access.c @@ -21,5 +21,5 @@ int access (char const *file_name, int how) { - return _sys_call2 (SYS_access, (long)file_name, (int)how); + return _sys_call2 (SYS_access, (long) file_name, (int) how); } diff --git a/lib/linux/brk.c b/lib/linux/brk.c index e727e73e..2d880218 100644 --- a/lib/linux/brk.c +++ b/lib/linux/brk.c @@ -21,5 +21,5 @@ long brk (void *addr) { - return _sys_call1 (SYS_brk, (long)addr); + return _sys_call1 (SYS_brk, (long) addr); } diff --git a/lib/linux/chdir.c b/lib/linux/chdir.c index 43d522cf..12f2e2e4 100644 --- a/lib/linux/chdir.c +++ b/lib/linux/chdir.c @@ -21,5 +21,5 @@ int chdir (char const *file_name) { - return _sys_call1 (SYS_chdir, (long)file_name); + return _sys_call1 (SYS_chdir, (long) file_name); } diff --git a/lib/linux/chmod.c b/lib/linux/chmod.c index a2380f78..6a7e76a5 100644 --- a/lib/linux/chmod.c +++ b/lib/linux/chmod.c @@ -21,5 +21,5 @@ int chmod (char const *file_name, mode_t mask) { - return _sys_call2 (SYS_chmod, (long)file_name, (long)mask); + return _sys_call2 (SYS_chmod, (long) file_name, (long) mask); } diff --git a/lib/linux/clock_gettime.c b/lib/linux/clock_gettime.c index a23572eb..ee6a385e 100644 --- a/lib/linux/clock_gettime.c +++ b/lib/linux/clock_gettime.c @@ -23,5 +23,5 @@ int clock_gettime (clockid_t clk_id, struct timespec *tp) { - return _sys_call2 (SYS_clock_gettime, (long)clk_id, (long)tp); + return _sys_call2 (SYS_clock_gettime, (long) clk_id, (long) tp); } diff --git a/lib/linux/close.c b/lib/linux/close.c index 7876169e..591031b7 100644 --- a/lib/linux/close.c +++ b/lib/linux/close.c @@ -23,5 +23,5 @@ close (int filedes) { if (filedes > 2) __ungetc_buf[filedes] = -1; - return _sys_call1 (SYS_close, (int)filedes); + return _sys_call1 (SYS_close, (int) filedes); } diff --git a/lib/linux/dup.c b/lib/linux/dup.c index f7c8c512..5a5bd5d0 100644 --- a/lib/linux/dup.c +++ b/lib/linux/dup.c @@ -21,5 +21,5 @@ int dup (int old) { - return _sys_call1 (SYS_dup, (int)old); + return _sys_call1 (SYS_dup, (int) old); } diff --git a/lib/linux/dup2.c b/lib/linux/dup2.c index 36cf5460..c93fdbd2 100644 --- a/lib/linux/dup2.c +++ b/lib/linux/dup2.c @@ -21,5 +21,5 @@ int dup2 (int old, int new) { - return _sys_call2 (SYS_dup2, (int)old, (int)new); + return _sys_call2 (SYS_dup2, (int) old, (int) new); } diff --git a/lib/linux/execve.c b/lib/linux/execve.c index fe747322..477ada92 100644 --- a/lib/linux/execve.c +++ b/lib/linux/execve.c @@ -19,7 +19,7 @@ */ int -execve (char const* file_name, char *const argv[], char *const env[]) +execve (char const *file_name, char *const argv[], char *const env[]) { - return _sys_call3 (SYS_execve, (long)file_name, (long)argv, (long)env); + return _sys_call3 (SYS_execve, (long) file_name, (long) argv, (long) env); } diff --git a/lib/linux/fcntl.c b/lib/linux/fcntl.c index 3fb291b7..c923a3dc 100644 --- a/lib/linux/fcntl.c +++ b/lib/linux/fcntl.c @@ -24,7 +24,7 @@ fcntl (int filedes, int command, ...) va_list ap; va_start (ap, command); int data = va_arg (ap, int); - int r = _sys_call3 (SYS_fcntl, (int)filedes, (int)command, (int)data); + int r = _sys_call3 (SYS_fcntl, (int) filedes, (int) command, (int) data); va_end (ap); return r; } diff --git a/lib/linux/fstat.c b/lib/linux/fstat.c index 48aabcab..ca31e184 100644 --- a/lib/linux/fstat.c +++ b/lib/linux/fstat.c @@ -21,5 +21,5 @@ int fstat (int filedes, struct stat *statbuf) { - return _sys_call2 (SYS_fstat, (int)filedes, (long)statbuf); + return _sys_call2 (SYS_fstat, (int) filedes, (long) statbuf); } diff --git a/lib/linux/fsync.c b/lib/linux/fsync.c index afe12693..7a584de1 100644 --- a/lib/linux/fsync.c +++ b/lib/linux/fsync.c @@ -21,5 +21,5 @@ int fsync (int filedes) { - return _sys_call1 (SYS_fsync, (int)filedes); + return _sys_call1 (SYS_fsync, (int) filedes); } diff --git a/lib/linux/getcwd.c b/lib/linux/getcwd.c index 91ded19e..847a6dcf 100644 --- a/lib/linux/getcwd.c +++ b/lib/linux/getcwd.c @@ -21,7 +21,7 @@ char * _getcwd (char *buffer, size_t size) { - int r = _sys_call2 (SYS_getcwd, (long)buffer, (long)size); + int r = _sys_call2 (SYS_getcwd, (long) buffer, (long) size); if (r >= 0) return buffer; return 0; diff --git a/lib/linux/getdents.c b/lib/linux/getdents.c index e4b1dda4..16a5567c 100644 --- a/lib/linux/getdents.c +++ b/lib/linux/getdents.c @@ -21,5 +21,5 @@ int getdents (int filedes, char *buffer, size_t nbytes) { - return _sys_call3 (SYS_getdents, (int)filedes, (long)buffer, (long)nbytes); + return _sys_call3 (SYS_getdents, (int) filedes, (long) buffer, (long) nbytes); } diff --git a/lib/linux/getrusage.c b/lib/linux/getrusage.c index 56aaf208..b9e84611 100644 --- a/lib/linux/getrusage.c +++ b/lib/linux/getrusage.c @@ -21,5 +21,5 @@ int getrusage (int processes, struct rusage *rusage) { - return _sys_call2 (SYS_getrusage, (int)processes, (long)rusage); + return _sys_call2 (SYS_getrusage, (int) processes, (long) rusage); } diff --git a/lib/linux/gettimeofday.c b/lib/linux/gettimeofday.c index 81cf0fc0..6cef5653 100644 --- a/lib/linux/gettimeofday.c +++ b/lib/linux/gettimeofday.c @@ -23,5 +23,5 @@ int gettimeofday (struct timeval *tv, struct timezone *tz) { - return _sys_call2 (SYS_gettimeofday, (long)tv, (long)tz); + return _sys_call2 (SYS_gettimeofday, (long) tv, (long) tz); } diff --git a/lib/linux/ioctl.c b/lib/linux/ioctl.c index 9c9dfede..8b4f9fae 100644 --- a/lib/linux/ioctl.c +++ b/lib/linux/ioctl.c @@ -24,7 +24,7 @@ ioctl (int filedes, unsigned long command, ...) va_list ap; va_start (ap, command); int data = va_arg (ap, int); - int r = _sys_call3 (SYS_ioctl, (int)filedes, (long)command, (int)data); + int r = _sys_call3 (SYS_ioctl, (int) filedes, (long) command, (int) data); va_end (ap); return r; } diff --git a/lib/linux/kill.c b/lib/linux/kill.c index 4aeeeeb3..174886ba 100644 --- a/lib/linux/kill.c +++ b/lib/linux/kill.c @@ -21,5 +21,5 @@ int kill (pid_t pid, int signum) { - return _sys_call2 (SYS_kill, (long)pid, (long)signum); + return _sys_call2 (SYS_kill, (long) pid, (long) signum); } diff --git a/lib/linux/link.c b/lib/linux/link.c index 7d9893b7..2b13af0e 100644 --- a/lib/linux/link.c +++ b/lib/linux/link.c @@ -21,5 +21,5 @@ int link (char const *old_name, char const *new_name) { - return _sys_call2 (SYS_link, (long)old_name, (long)new_name); + return _sys_call2 (SYS_link, (long) old_name, (long) new_name); } diff --git a/lib/linux/lseek.c b/lib/linux/lseek.c index 7f6fc85a..ca673133 100644 --- a/lib/linux/lseek.c +++ b/lib/linux/lseek.c @@ -21,5 +21,5 @@ off_t lseek (int filedes, off_t offset, int whence) { - return _sys_call3 (SYS_lseek, (int)filedes, (long)offset, (int)whence); + return _sys_call3 (SYS_lseek, (int) filedes, (long) offset, (int) whence); } diff --git a/lib/linux/lstat.c b/lib/linux/lstat.c index c3ca9cbf..c091181b 100644 --- a/lib/linux/lstat.c +++ b/lib/linux/lstat.c @@ -21,5 +21,5 @@ int lstat (char const *file_name, struct stat *statbuf) { - return _sys_call2 (SYS_lstat, (long)file_name, (long)statbuf); + return _sys_call2 (SYS_lstat, (long) file_name, (long) statbuf); } diff --git a/lib/linux/mkdir.c b/lib/linux/mkdir.c index 1f5a1af1..cadb60c8 100644 --- a/lib/linux/mkdir.c +++ b/lib/linux/mkdir.c @@ -21,5 +21,5 @@ int mkdir (char const *file_name, mode_t mode) { - return _sys_call2 (SYS_mkdir, (long)file_name, (long)mode); + return _sys_call2 (SYS_mkdir, (long) file_name, (long) mode); } diff --git a/lib/linux/nanosleep.c b/lib/linux/nanosleep.c index f5c02b45..0172b200 100644 --- a/lib/linux/nanosleep.c +++ b/lib/linux/nanosleep.c @@ -19,8 +19,7 @@ */ int -nanosleep (const struct timespec *requested_time, - struct timespec *remaining) +nanosleep (const struct timespec *requested_time, struct timespec *remaining) { - return _sys_call2 (SYS_nanosleep, (long)requested_time, (long)remaining); + return _sys_call2 (SYS_nanosleep, (long) requested_time, (long) remaining); } diff --git a/lib/linux/open.c b/lib/linux/open.c index 5eca8c35..951e50ed 100644 --- a/lib/linux/open.c +++ b/lib/linux/open.c @@ -21,7 +21,7 @@ int _open3 (char const *file_name, int flags, int mask) { - int r = _sys_call3 (SYS_open, (long)file_name, (int)flags, (int)mask); + int r = _sys_call3 (SYS_open, (long) file_name, (int) flags, (int) mask); __ungetc_init (); if (r > 2) __ungetc_buf[r] = -1; diff --git a/lib/linux/pipe.c b/lib/linux/pipe.c index ba510660..4fbfd4ad 100644 --- a/lib/linux/pipe.c +++ b/lib/linux/pipe.c @@ -21,5 +21,5 @@ int pipe (int filedes[2]) { - return _sys_call1 (SYS_pipe, (long)filedes); + return _sys_call1 (SYS_pipe, (long) filedes); } diff --git a/lib/linux/read.c b/lib/linux/read.c index 8547a6ca..9c3917c2 100644 --- a/lib/linux/read.c +++ b/lib/linux/read.c @@ -21,17 +21,24 @@ ssize_t read (int filedes, void *buffer, size_t size) { - ssize_t bytes = _sys_call3 (SYS_read, (int)filedes, (long)buffer, (long)size); + ssize_t bytes = _sys_call3 (SYS_read, (int) filedes, (long) buffer, (long) size); if (__mes_debug () > 3) { if (bytes == 1) { - eputs ("read fd="); eputs (itoa ((int)filedes)); eputs (" c="); eputc (*(char*)buffer); eputs ("\n"); + eputs ("read fd="); + eputs (itoa ((int) filedes)); + eputs (" c="); + eputc (*(char *) buffer); + eputs ("\n"); } else { - eputs ("read fd="); eputs (itoa ((int)filedes)); - eputs (" bytes="); eputs (itoa (bytes)); eputs ("\n"); + eputs ("read fd="); + eputs (itoa ((int) filedes)); + eputs (" bytes="); + eputs (itoa (bytes)); + eputs ("\n"); } } return bytes; diff --git a/lib/linux/rename.c b/lib/linux/rename.c index 56a8a5b9..6acc00a5 100644 --- a/lib/linux/rename.c +++ b/lib/linux/rename.c @@ -21,5 +21,5 @@ int rename (char const *old_name, char const *new_name) { - return _sys_call2 (SYS_rename, (long)old_name, (long)new_name); + return _sys_call2 (SYS_rename, (long) old_name, (long) new_name); } diff --git a/lib/linux/rmdir.c b/lib/linux/rmdir.c index ab95d231..e923b853 100644 --- a/lib/linux/rmdir.c +++ b/lib/linux/rmdir.c @@ -21,5 +21,5 @@ int rmdir (char const *file_name) { - return _sys_call1 (SYS_rmdir, (long)file_name); + return _sys_call1 (SYS_rmdir, (long) file_name); } diff --git a/lib/linux/setgid.c b/lib/linux/setgid.c index 9b11e0a9..468be9cc 100644 --- a/lib/linux/setgid.c +++ b/lib/linux/setgid.c @@ -21,5 +21,5 @@ int setgid (gid_t newgid) { - return _sys_call1 (SYS_setgid, (long)newgid); + return _sys_call1 (SYS_setgid, (long) newgid); } diff --git a/lib/linux/settimer.c b/lib/linux/settimer.c index 28fd3c9e..6ca2ac2c 100644 --- a/lib/linux/settimer.c +++ b/lib/linux/settimer.c @@ -19,8 +19,7 @@ */ int -setitimer (int which, struct itimerval const *new, - struct itimerval *old) +setitimer (int which, struct itimerval const *new, struct itimerval *old) { - return _sys_call3 (SYS_setitimer, (long)which, (long)new, (long)old); + return _sys_call3 (SYS_setitimer, (long) which, (long) new, (long) old); } diff --git a/lib/linux/setuid.c b/lib/linux/setuid.c index 33a73303..7d317816 100644 --- a/lib/linux/setuid.c +++ b/lib/linux/setuid.c @@ -21,5 +21,5 @@ int setuid (uid_t newuid) { - return _sys_call1 (SYS_setuid, (long)newuid); + return _sys_call1 (SYS_setuid, (long) newuid); } diff --git a/lib/linux/signal.c b/lib/linux/signal.c index 72b66512..3e33ada8 100644 --- a/lib/linux/signal.c +++ b/lib/linux/signal.c @@ -35,8 +35,8 @@ signal (int signum, sighandler_t action) #if __i386__ return _sys_call2 (SYS_signal, signum, action); #else - static struct sigaction setup_action = {-1}; - static struct sigaction old = {0}; + static struct sigaction setup_action = { -1 }; + static struct sigaction old = { 0 }; setup_action.sa_handler = action; setup_action.sa_restorer = _restorer; diff --git a/lib/linux/sigprogmask.c b/lib/linux/sigprogmask.c index 13ae60cf..40d9ff41 100644 --- a/lib/linux/sigprogmask.c +++ b/lib/linux/sigprogmask.c @@ -19,11 +19,11 @@ */ int -sigprocmask (int how, sigset_t const *set, sigset_t *oldset) +sigprocmask (int how, sigset_t const *set, sigset_t * oldset) { #if __i386__ - return _sys_call3 (SYS_sigprocmask, (long)how, (long)set, (long)oldset); + return _sys_call3 (SYS_sigprocmask, (long) how, (long) set, (long) oldset); #else - return _sys_call3 (SYS_rt_sigprocmask, (long)how, (long)set, (long)oldset); + return _sys_call3 (SYS_rt_sigprocmask, (long) how, (long) set, (long) oldset); #endif } diff --git a/lib/linux/stat.c b/lib/linux/stat.c index 3f9e43c4..d34c73d8 100644 --- a/lib/linux/stat.c +++ b/lib/linux/stat.c @@ -21,5 +21,5 @@ int stat (char const *file_name, struct stat *statbuf) { - return _sys_call2 (SYS_stat, (long)file_name, (long)statbuf); + return _sys_call2 (SYS_stat, (long) file_name, (long) statbuf); } diff --git a/lib/linux/time.c b/lib/linux/time.c index 863a13c9..1b4acc52 100644 --- a/lib/linux/time.c +++ b/lib/linux/time.c @@ -21,7 +21,7 @@ #include time_t -time (time_t *result) +time (time_t * result) { - return _sys_call1 (SYS_time, (long)result); + return _sys_call1 (SYS_time, (long) result); } diff --git a/lib/linux/unlink.c b/lib/linux/unlink.c index 989c198a..97e6ef90 100644 --- a/lib/linux/unlink.c +++ b/lib/linux/unlink.c @@ -21,5 +21,5 @@ int unlink (char const *file_name) { - return _sys_call1 (SYS_unlink, (long)file_name); + return _sys_call1 (SYS_unlink, (long) file_name); } diff --git a/lib/linux/waitpid.c b/lib/linux/waitpid.c index 048a5ac8..3d3aa0bb 100644 --- a/lib/linux/waitpid.c +++ b/lib/linux/waitpid.c @@ -22,9 +22,9 @@ pid_t waitpid (pid_t pid, int *status_ptr, int options) { #if __i386__ - return _sys_call3 (SYS_waitpid, (long)pid, (long)status_ptr, (int)options); + return _sys_call3 (SYS_waitpid, (long) pid, (long) status_ptr, (int) options); #elif __x86_64__ - return _sys_call4 (SYS_wait4, (long)pid, (long)status_ptr, (int)options, 0); + return _sys_call4 (SYS_wait4, (long) pid, (long) status_ptr, (int) options, 0); #else #error arch not supported #endif diff --git a/lib/linux/x86_64-mes/crt1.c b/lib/linux/x86_64-mes/crt1.c index 6449a99d..0161c93b 100644 --- a/lib/linux/x86_64-mes/crt1.c +++ b/lib/linux/x86_64-mes/crt1.c @@ -33,8 +33,8 @@ _start () asm ("mov____$i8,%rax !2"); asm ("mov____%rax,0x32 &__stderr"); -#if 0 //MES_CCAMD64 - asm ("add____$i32,%rbp %0x80"); // FIXME: corresponds to x86_64/as.scm function-preamble-fu +#if 0 //MES_CCAMD64 + asm ("add____$i32,%rbp %0x80"); // FIXME: corresponds to x86_64/as.scm function-preamble-fu #endif asm ("mov____%rbp,%rax"); asm ("add____$i8,%rax !8"); @@ -47,7 +47,7 @@ _start () // FIXME: 64-bit addresses... asm ("mov____%rax,0x32 &environ"); -#if 0 //MES_CCAMD64 +#if 0 //MES_CCAMD64 asm ("mov____%rax,%rdx"); // amd #else asm ("push___%rax"); // bootstrap @@ -55,7 +55,7 @@ _start () asm ("mov____%rbp,%rax"); asm ("add____$i8,%rax !16"); -#if 0 //MES_CCAMD64 +#if 0 //MES_CCAMD64 asm ("mov____%rax,%rsi"); // amd #else asm ("push___%rax"); // bootstrap @@ -64,7 +64,7 @@ _start () asm ("mov____%rbp,%rax"); asm ("add____$i8,%rax !8"); asm ("mov____(%rax),%rax"); -#if 0 //MES_CCAMD64 +#if 0 //MES_CCAMD64 asm ("mov____%rax,%rdi"); // amd #else asm ("push___%rax"); // bootstrap diff --git a/lib/linux/x86_64-mes/mes.c b/lib/linux/x86_64-mes/mes.c index e87656b3..cc64037b 100644 --- a/lib/linux/x86_64-mes/mes.c +++ b/lib/linux/x86_64-mes/mes.c @@ -25,7 +25,7 @@ long //__sys_call (long one, long two, long three, long four) __sys_call (long sys_call, long one, long two, long three, long four) { -#if 1 // !MES_CCAMD64 +#if 1 // !MES_CCAMD64 // asm ("mov____0x8(%rbp),%rdi !0x10"); // asm ("mov____0x8(%rbp),%rsi !0x18"); // asm ("mov____0x8(%rbp),%rdx !0x20"); diff --git a/lib/linux/x86_64-mes/mini.c b/lib/linux/x86_64-mes/mini.c index c5816727..15fcf244 100644 --- a/lib/linux/x86_64-mes/mini.c +++ b/lib/linux/x86_64-mes/mini.c @@ -21,7 +21,7 @@ void _exit (int status) { -#if 1 // !MES_CCAMD64 +#if 1 // !MES_CCAMD64 asm ("mov____0x8(%rbp),%rdi !0x10"); #endif @@ -32,7 +32,7 @@ _exit (int status) void _write (int filedes, void const *buffer, size_t size) { -#if 1 // !MES_CCAMD64 +#if 1 // !MES_CCAMD64 asm ("mov____0x8(%rbp),%rdi !0x10"); asm ("mov____0x8(%rbp),%rsi !0x18"); asm ("mov____0x8(%rbp),%rdx !0x20"); diff --git a/lib/mes/eputs.c b/lib/mes/eputs.c index bc3997af..8aa75207 100644 --- a/lib/mes/eputs.c +++ b/lib/mes/eputs.c @@ -21,7 +21,7 @@ #include int -eputs (char const* s) +eputs (char const *s) { int i = strlen (s); write (__stderr, s, i); diff --git a/lib/mes/fdgetc.c b/lib/mes/fdgetc.c index 373474c6..74dfb27b 100644 --- a/lib/mes/fdgetc.c +++ b/lib/mes/fdgetc.c @@ -22,13 +22,13 @@ #include #include -int __ungetc_buf[RLIMIT_NOFILE+1] = {0}; +int __ungetc_buf[RLIMIT_NOFILE + 1] = { 0 }; void __ungetc_init () { if (__ungetc_buf[RLIMIT_NOFILE] == 0) - memset (__ungetc_buf, -1, (RLIMIT_NOFILE+1)*sizeof (int)); + memset (__ungetc_buf, -1, (RLIMIT_NOFILE + 1) * sizeof (int)); } int @@ -46,7 +46,7 @@ fdgetc (int fd) if (r < 1) return -1; i = c; - } + } if (i < 0) i += 256; diff --git a/lib/mes/fdputc.c b/lib/mes/fdputc.c index bd1eda43..0e68195b 100644 --- a/lib/mes/fdputc.c +++ b/lib/mes/fdputc.c @@ -23,6 +23,6 @@ int fdputc (int c, int fd) { - write (fd, (char*)&c, 1); + write (fd, (char *) &c, 1); return 0; } diff --git a/lib/mes/fdputs.c b/lib/mes/fdputs.c index 784fc0c5..73063dcb 100644 --- a/lib/mes/fdputs.c +++ b/lib/mes/fdputs.c @@ -21,7 +21,7 @@ #include int -fdputs (char const* s, int fd) +fdputs (char const *s, int fd) { int i = strlen (s); write (fd, s, i); diff --git a/lib/mes/ntoab.c b/lib/mes/ntoab.c index 26e60fe9..3166015f 100644 --- a/lib/mes/ntoab.c +++ b/lib/mes/ntoab.c @@ -36,14 +36,15 @@ ntoab (long x, int base, int signed_p) } do - { - long i = u % base; - *p-- = i > 9 ? 'a' + i - 10 : '0' + i; - u = u / base; - } while (u); + { + long i = u % base; + *p-- = i > 9 ? 'a' + i - 10 : '0' + i; + u = u / base; + } + while (u); if (sign && *(p + 1) != '0') *p-- = '-'; - return p+1; + return p + 1; } diff --git a/lib/mes/oputs.c b/lib/mes/oputs.c index 82731528..bcdf9d98 100644 --- a/lib/mes/oputs.c +++ b/lib/mes/oputs.c @@ -21,7 +21,7 @@ #include int -oputs (char const* s) +oputs (char const *s) { int i = strlen (s); write (__stdout, s, i); diff --git a/lib/mes/search-path.c b/lib/mes/search-path.c index 035ac6c1..8398babb 100644 --- a/lib/mes/search-path.c +++ b/lib/mes/search-path.c @@ -27,7 +27,9 @@ search_path (char const *file_name) char *path = getenv ("PATH"); if (__mes_debug ()) { - eputs ("\n search-path: "); eputs (file_name); eputs ("\n"); + eputs ("\n search-path: "); + eputs (file_name); + eputs ("\n"); } while (*path) { @@ -38,7 +40,9 @@ search_path (char const *file_name) buf[end - path] = 0; if (__mes_debug ()) { - eputs (" dir: "); eputs (buf); eputs ("\n"); + eputs (" dir: "); + eputs (buf); + eputs ("\n"); } if (buf[end - path] != '/') strcat (buf, "/"); @@ -47,7 +51,9 @@ search_path (char const *file_name) { if (__mes_debug ()) { - eputs (" found: "); eputs (buf); eputs ("\n"); + eputs (" found: "); + eputs (buf); + eputs ("\n"); } return buf; } diff --git a/lib/posix/execl.c b/lib/posix/execl.c index e5f89c1b..59182549 100644 --- a/lib/posix/execl.c +++ b/lib/posix/execl.c @@ -26,9 +26,11 @@ execl (char const *file_name, char const *arg, ...) { if (__mes_debug () > 2) { - eputs ("execl "); eputs (file_name); eputs ("\n"); + eputs ("execl "); + eputs (file_name); + eputs ("\n"); } - char *argv[1000]; // POSIX minimum 4096 + char *argv[1000]; // POSIX minimum 4096 int i = 0; va_list ap; @@ -42,7 +44,11 @@ execl (char const *file_name, char const *arg, ...) arg = va_arg (ap, char const *); if (__mes_debug () > 2) { - eputs ("arg["); eputs (itoa (i)); eputs ("]: "); eputs (argv[i-1]); eputs ("\n"); + eputs ("arg["); + eputs (itoa (i)); + eputs ("]: "); + eputs (argv[i - 1]); + eputs ("\n"); } } argv[i] = 0; diff --git a/lib/posix/execvp.c b/lib/posix/execvp.c index 74476d8a..bc801375 100644 --- a/lib/posix/execvp.c +++ b/lib/posix/execvp.c @@ -33,11 +33,17 @@ execvp (char const *file_name, char *const argv[]) } if (__mes_debug ()) { - eputs (" EXEC: "); eputs (file_name); eputs ("\n"); + eputs (" EXEC: "); + eputs (file_name); + eputs ("\n"); int i = 0; while (argv[i]) { - eputs (" arg["); eputs (itoa (i)); eputs ("]: "); eputs (argv[i]); eputs ("\n"); + eputs (" arg["); + eputs (itoa (i)); + eputs ("]: "); + eputs (argv[i]); + eputs ("\n"); i++; } } diff --git a/lib/posix/getenv.c b/lib/posix/getenv.c index fdf42f5e..8b58d635 100644 --- a/lib/posix/getenv.c +++ b/lib/posix/getenv.c @@ -21,7 +21,7 @@ #include char * -getenv (char const* s) +getenv (char const *s) { char **p = environ; int length = strlen (s); diff --git a/lib/posix/getopt.c b/lib/posix/getopt.c index 956a1052..1a9d30d7 100644 --- a/lib/posix/getopt.c +++ b/lib/posix/getopt.c @@ -58,8 +58,8 @@ static char *nextchar; for unrecognized options. */ int opterr = 1; - + /* Handle permutation of arguments. */ /* Describe the part of ARGV that contains non-options that have @@ -68,8 +68,8 @@ int opterr = 1; static int first_nonopt; static int last_nonopt; - + /* Scan elements of ARGV (whose length is ARGC) for option characters given in OPTSTRING. @@ -148,33 +148,30 @@ _getopt_internal (int argc, char *const if (nextchar == NULL || *nextchar == '\0') { /* If we have done all the ARGV-elements, stop the scan - and back over any non-options that we skipped and permuted. */ + and back over any non-options that we skipped and permuted. */ if (optind == argc) - { - /* Set the next-arg-index to point at the non-options - that we previously skipped, so the caller will digest them. */ - if (first_nonopt != last_nonopt) - optind = first_nonopt; - return EOF; - } + { + /* Set the next-arg-index to point at the non-options + that we previously skipped, so the caller will digest them. */ + if (first_nonopt != last_nonopt) + optind = first_nonopt; + return EOF; + } /* If we have come to a non-option and did not permute it, - either stop the scan or describe it to the caller and pass it by. */ + either stop the scan or describe it to the caller and pass it by. */ if ((argv[optind][0] != '-' || argv[optind][1] == '\0')) return EOF; /* We have found another option-ARGV-element. - Start decoding its characters. */ + Start decoding its characters. */ - nextchar = (argv[optind] + 1 - + (longopts != NULL && argv[optind][1] == '-')); + nextchar = (argv[optind] + 1 + (longopts != NULL && argv[optind][1] == '-')); } - if (longopts != NULL - && ((argv[optind][0] == '-' - && (argv[optind][1] == '-' || long_only)))) + if (longopts != NULL && ((argv[optind][0] == '-' && (argv[optind][1] == '-' || long_only)))) { const struct option *p; char *s = nextchar; @@ -184,116 +181,109 @@ _getopt_internal (int argc, char *const int indfound; while (*s && *s != '=') - s++; + s++; /* Test all options for either exact match or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; - p++, option_index++) - if (!strncmp (p->name, nextchar, s - nextchar)) - { - if (s - nextchar == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second nonexact match found. */ - ambig = 1; - } + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp (p->name, nextchar, s - nextchar)) + { + if (s - nextchar == strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else + /* Second nonexact match found. */ + ambig = 1; + } if (ambig && !exact) - { - if (opterr) - fprintf (stderr, "%s: option `%s' is ambiguous\n", - argv[0], argv[optind]); - nextchar += strlen (nextchar); - optind++; - return '?'; - } + { + if (opterr) + fprintf (stderr, "%s: option `%s' is ambiguous\n", argv[0], argv[optind]); + nextchar += strlen (nextchar); + optind++; + return '?'; + } if (pfound != NULL) - { - option_index = indfound; - optind++; - if (*s) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - optarg = s + 1; - else - { - if (opterr) - { - if (argv[optind - 1][1] == '-') - /* --option */ - fprintf (stderr, - "%s: option `--%s' doesn't allow an argument\n", - argv[0], pfound->name); - else - /* +option or -option */ - fprintf (stderr, - "%s: option `%c%s' doesn't allow an argument\n", - argv[0], argv[optind - 1][0], pfound->name); - } - nextchar += strlen (nextchar); - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (optind < argc) - optarg = argv[optind++]; - else - { - if (opterr) - fprintf (stderr, "%s: option `%s' requires an argument\n", - argv[0], argv[optind - 1]); - nextchar += strlen (nextchar); - return '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } + { + option_index = indfound; + optind++; + if (*s) + { + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + optarg = s + 1; + else + { + if (opterr) + { + if (argv[optind - 1][1] == '-') + /* --option */ + fprintf (stderr, + "%s: option `--%s' doesn't allow an argument\n", argv[0], pfound->name); + else + /* +option or -option */ + fprintf (stderr, + "%s: option `%c%s' doesn't allow an argument\n", + argv[0], argv[optind - 1][0], pfound->name); + } + nextchar += strlen (nextchar); + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (optind < argc) + optarg = argv[optind++]; + else + { + if (opterr) + fprintf (stderr, "%s: option `%s' requires an argument\n", argv[0], argv[optind - 1]); + nextchar += strlen (nextchar); + return '?'; + } + } + nextchar += strlen (nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } /* Can't find it as a long option. If this is not getopt_long_only, - or the option starts with '--' or is not a valid short - option, then it's an error. - Otherwise interpret it as a short option. */ - if (!long_only || argv[optind][1] == '-' - || strchr (optstring, *nextchar) == NULL) - { - if (opterr) - { - if (argv[optind][1] == '-') - /* --option */ - fprintf (stderr, "%s: unrecognized option `--%s'\n", - argv[0], nextchar); - else - /* +option or -option */ - fprintf (stderr, "%s: unrecognized option `%c%s'\n", - argv[0], argv[optind][0], nextchar); - } - nextchar += strlen (nextchar); - optind++; - return '?'; - } + or the option starts with '--' or is not a valid short + option, then it's an error. + Otherwise interpret it as a short option. */ + if (!long_only || argv[optind][1] == '-' || strchr (optstring, *nextchar) == NULL) + { + if (opterr) + { + if (argv[optind][1] == '-') + /* --option */ + fprintf (stderr, "%s: unrecognized option `--%s'\n", argv[0], nextchar); + else + /* +option or -option */ + fprintf (stderr, "%s: unrecognized option `%c%s'\n", argv[0], argv[optind][0], nextchar); + } + nextchar += strlen (nextchar); + optind++; + return '?'; + } } /* Look at and handle the next option-character. */ @@ -308,53 +298,51 @@ _getopt_internal (int argc, char *const if (temp == NULL || c == ':') { - if (opterr) - { - if (c < 040 || c >= 0177) - fprintf (stderr, "%s: unrecognized option, character code 0%o\n", - argv[0], c); - else - fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c); - } - return '?'; + if (opterr) + { + if (c < 040 || c >= 0177) + fprintf (stderr, "%s: unrecognized option, character code 0%o\n", argv[0], c); + else + fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c); + } + return '?'; } if (temp[1] == ':') { - if (temp[2] == ':') - { - /* This is an option that accepts an argument optionally. */ - if (*nextchar != '\0') - { - optarg = nextchar; - optind++; - } - else - optarg = 0; - nextchar = NULL; - } - else - { - /* This is an option that requires an argument. */ - if (*nextchar != 0) - { - optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - optind++; - } - else if (optind == argc) - { - if (opterr) - fprintf (stderr, "%s: option `-%c' requires an argument\n", - argv[0], c); - c = '?'; - } - else - /* We already incremented `optind' once; - increment it again when taking next ARGV-elt as argument. */ - optarg = argv[optind++]; - nextchar = NULL; - } + if (temp[2] == ':') + { + /* This is an option that accepts an argument optionally. */ + if (*nextchar != '\0') + { + optarg = nextchar; + optind++; + } + else + optarg = 0; + nextchar = NULL; + } + else + { + /* This is an option that requires an argument. */ + if (*nextchar != 0) + { + optarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + optind++; + } + else if (optind == argc) + { + if (opterr) + fprintf (stderr, "%s: option `-%c' requires an argument\n", argv[0], c); + c = '?'; + } + else + /* We already incremented `optind' once; + increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + nextchar = NULL; + } } return c; } @@ -363,8 +351,7 @@ _getopt_internal (int argc, char *const int getopt (int argc, char *const *argv, char const *options) { - return _getopt_internal (argc, argv, options, - (const struct option *) 0, (int *) 0, 0); + return _getopt_internal (argc, argv, options, (const struct option *) 0, (int *) 0, 0); } int diff --git a/lib/posix/mktemp.c b/lib/posix/mktemp.c index 0c7e5164..8226b5f9 100644 --- a/lib/posix/mktemp.c +++ b/lib/posix/mktemp.c @@ -24,12 +24,12 @@ char * mktemp (char *template) { char *p = strchr (template, '\0'); - int q = (long)template; - *--p = ((unsigned char)(q >> 4)) % 26 + 'a'; - *--p = ((unsigned char)(q >> 8)) % 26 + 'a'; - *--p = ((unsigned char)(q >> 12)) % 26 + 'a'; - *--p = ((unsigned char)(q >> 16)) % 26 + 'a'; - *--p = ((unsigned char)(q >> 20)) % 26 + 'a'; - *--p = ((unsigned char)(q >> 24)) % 26 + 'a'; + int q = (long) template; + *--p = ((unsigned char) (q >> 4)) % 26 + 'a'; + *--p = ((unsigned char) (q >> 8)) % 26 + 'a'; + *--p = ((unsigned char) (q >> 12)) % 26 + 'a'; + *--p = ((unsigned char) (q >> 16)) % 26 + 'a'; + *--p = ((unsigned char) (q >> 20)) % 26 + 'a'; + *--p = ((unsigned char) (q >> 24)) % 26 + 'a'; return template; } diff --git a/lib/posix/setenv.c b/lib/posix/setenv.c index ecaac2c4..c8de6087 100644 --- a/lib/posix/setenv.c +++ b/lib/posix/setenv.c @@ -21,7 +21,7 @@ #include int -setenv (char const* s, char const* v, int overwrite_p) +setenv (char const *s, char const *v, int overwrite_p) { char **p = environ; int length = strlen (s); diff --git a/lib/posix/wait.c b/lib/posix/wait.c index a9bb1f4c..5ec0f1c6 100644 --- a/lib/posix/wait.c +++ b/lib/posix/wait.c @@ -23,5 +23,5 @@ pid_t wait (int *status_ptr) { - return waitpid (-1, status_ptr, 0); + return waitpid (-1, status_ptr, 0); } diff --git a/lib/stdio/clearerr.c b/lib/stdio/clearerr.c index 3be2ba9c..4c0729e9 100644 --- a/lib/stdio/clearerr.c +++ b/lib/stdio/clearerr.c @@ -21,7 +21,7 @@ #include void -clearerr (FILE *stream) +clearerr (FILE * stream) { errno = 0; } diff --git a/lib/stdio/fclose.c b/lib/stdio/fclose.c index 29192de2..04ffbfa8 100644 --- a/lib/stdio/fclose.c +++ b/lib/stdio/fclose.c @@ -21,8 +21,8 @@ #include int -fclose (FILE *stream) +fclose (FILE * stream) { - int fd = (int)stream; + int fd = (int) stream; return close (fd); } diff --git a/lib/stdio/fdopen.c b/lib/stdio/fdopen.c index eb39d7c2..4be1adcd 100644 --- a/lib/stdio/fdopen.c +++ b/lib/stdio/fdopen.c @@ -23,5 +23,5 @@ FILE * fdopen (int fd, char const *mode) { - return (FILE*)fd; + return (FILE *) fd; } diff --git a/lib/stdio/feof.c b/lib/stdio/feof.c index 0e7149fd..581dfb4c 100644 --- a/lib/stdio/feof.c +++ b/lib/stdio/feof.c @@ -21,7 +21,7 @@ #include int -feof (FILE *stream) +feof (FILE * stream) { char c = fgetc (stream); if (c != EOF) diff --git a/lib/stdio/ferror.c b/lib/stdio/ferror.c index 4e5582de..009f48b9 100644 --- a/lib/stdio/ferror.c +++ b/lib/stdio/ferror.c @@ -21,9 +21,9 @@ #include int -ferror (FILE *stream) +ferror (FILE * stream) { - int fd = (int)stream; + int fd = (int) stream; if (fd == -1) return -1; return 0; diff --git a/lib/stdio/fflush.c b/lib/stdio/fflush.c index c92587eb..3951bf1f 100644 --- a/lib/stdio/fflush.c +++ b/lib/stdio/fflush.c @@ -21,7 +21,7 @@ #include int -fflush (FILE *stream) +fflush (FILE * stream) { - fsync ((int)stream); + fsync ((int) stream); } diff --git a/lib/stdio/fgetc.c b/lib/stdio/fgetc.c index 83f2589c..0bca3f88 100644 --- a/lib/stdio/fgetc.c +++ b/lib/stdio/fgetc.c @@ -21,7 +21,7 @@ #include int -fgetc (FILE *stream) +fgetc (FILE * stream) { - return fdgetc ((long)stream); + return fdgetc ((long) stream); } diff --git a/lib/stdio/fgets.c b/lib/stdio/fgets.c index fb6d5f77..1635d5ab 100644 --- a/lib/stdio/fgets.c +++ b/lib/stdio/fgets.c @@ -21,7 +21,7 @@ #include char * -fgets (char *s, int count, FILE *stream) +fgets (char *s, int count, FILE * stream) { - return fdgets (s, count, (int)stream); + return fdgets (s, count, (int) stream); } diff --git a/lib/stdio/fileno.c b/lib/stdio/fileno.c index f5fe98ee..971f0667 100644 --- a/lib/stdio/fileno.c +++ b/lib/stdio/fileno.c @@ -21,7 +21,7 @@ #include int -fileno (FILE *stream) +fileno (FILE * stream) { - return (int)stream; + return (int) stream; } diff --git a/lib/stdio/fopen.c b/lib/stdio/fopen.c index 05ec8bbf..68f23e58 100644 --- a/lib/stdio/fopen.c +++ b/lib/stdio/fopen.c @@ -28,19 +28,21 @@ #define open _open3 #endif -FILE* +FILE * fopen (char const *file_name, char const *opentype) { if (__mes_debug ()) { - eputs ("fopen "); eputs (file_name); - eputs (" "); eputs (opentype); eputs ("\n"); + eputs ("fopen "); + eputs (file_name); + eputs (" "); + eputs (opentype); + eputs ("\n"); } int fd; int mode = 0600; - if ((opentype[0] == 'a' || !strcmp (opentype, "r+")) - && !access (file_name, O_RDONLY)) + if ((opentype[0] == 'a' || !strcmp (opentype, "r+")) && !access (file_name, O_RDONLY)) { int flags = O_RDWR; if (opentype[0] == 'a') @@ -58,7 +60,9 @@ fopen (char const *file_name, char const *opentype) if (__mes_debug ()) { - eputs (" => fd="); eputs (itoa (fd)); eputs ("\n"); + eputs (" => fd="); + eputs (itoa (fd)); + eputs ("\n"); } if (!fd) @@ -68,7 +72,7 @@ fopen (char const *file_name, char const *opentype) } if (fd < 0) fd = 0; - return (FILE*)fd; + return (FILE *) fd; } #undef open diff --git a/lib/stdio/fprintf.c b/lib/stdio/fprintf.c index 07e8c35a..c1ec5ceb 100644 --- a/lib/stdio/fprintf.c +++ b/lib/stdio/fprintf.c @@ -22,7 +22,7 @@ #include int -fprintf (FILE *stream, char const *format, ...) +fprintf (FILE * stream, char const *format, ...) { va_list ap; va_start (ap, format); diff --git a/lib/stdio/fputc.c b/lib/stdio/fputc.c index 264a2af3..232b534a 100644 --- a/lib/stdio/fputc.c +++ b/lib/stdio/fputc.c @@ -21,7 +21,7 @@ #include int -fputc (int c, FILE* stream) +fputc (int c, FILE * stream) { - return fdputc (c, (int)stream); + return fdputc (c, (int) stream); } diff --git a/lib/stdio/fputs.c b/lib/stdio/fputs.c index 165f0d2f..e4d913a4 100644 --- a/lib/stdio/fputs.c +++ b/lib/stdio/fputs.c @@ -21,7 +21,7 @@ #include int -fputs (char const* s, FILE* stream) +fputs (char const *s, FILE * stream) { - return fdputs (s, (long)stream); + return fdputs (s, (long) stream); } diff --git a/lib/stdio/fread.c b/lib/stdio/fread.c index 58a2c4c2..9b6f2e80 100644 --- a/lib/stdio/fread.c +++ b/lib/stdio/fread.c @@ -22,26 +22,26 @@ #include int -_fungetc_p (FILE *stream) +_fungetc_p (FILE * stream) { - return _fdungetc_p ((int)stream); + return _fdungetc_p ((int) stream); } size_t -fread (void *data, size_t size, size_t count, FILE *stream) +fread (void *data, size_t size, size_t count, FILE * stream) { - if (! size || !count) + if (!size || !count) return 0; size_t todo = size * count; - char *buf = (char*)data; + char *buf = (char *) data; int bytes = 0; while (_fungetc_p (stream) && todo-- && ++bytes) *buf++ = fgetc (stream); if (todo) { - int r = read ((int)stream, buf, todo); + int r = read ((int) stream, buf, todo); if (r < 0 && !bytes) bytes = r; else @@ -50,19 +50,24 @@ fread (void *data, size_t size, size_t count, FILE *stream) if (__mes_debug ()) { - eputs ("fread fd="); eputs (itoa ((int)stream)); - eputs (" bytes="); eputs (itoa (bytes)); eputs ("\n"); + eputs ("fread fd="); + eputs (itoa ((int) stream)); + eputs (" bytes="); + eputs (itoa (bytes)); + eputs ("\n"); static char buf[4096]; if (bytes > 0 && bytes < sizeof (buf)) { strncpy (buf, data, bytes); buf[bytes] = 0; - eputs ("fread buf="); eputs (buf); eputs ("\n"); + eputs ("fread buf="); + eputs (buf); + eputs ("\n"); } } if (bytes > 0) - return bytes/size; + return bytes / size; return 0; } diff --git a/lib/stdio/freeopen.c b/lib/stdio/freeopen.c index 757e48b8..f9447a09 100644 --- a/lib/stdio/freeopen.c +++ b/lib/stdio/freeopen.c @@ -21,7 +21,7 @@ #include FILE * -freopen (char const *file_name, char const *opentype, FILE *stream) +freopen (char const *file_name, char const *opentype, FILE * stream) { fclose (stream); return fopen (file_name, opentype); diff --git a/lib/stdio/freopen.c b/lib/stdio/freopen.c index 757e48b8..f9447a09 100644 --- a/lib/stdio/freopen.c +++ b/lib/stdio/freopen.c @@ -21,7 +21,7 @@ #include FILE * -freopen (char const *file_name, char const *opentype, FILE *stream) +freopen (char const *file_name, char const *opentype, FILE * stream) { fclose (stream); return fopen (file_name, opentype); diff --git a/lib/stdio/fseek.c b/lib/stdio/fseek.c index 281bfca0..62e5a4ff 100644 --- a/lib/stdio/fseek.c +++ b/lib/stdio/fseek.c @@ -22,13 +22,16 @@ #include int -fseek (FILE *stream, long offset, int whence) +fseek (FILE * stream, long offset, int whence) { - off_t pos = lseek ((int)stream, offset, whence); + off_t pos = lseek ((int) stream, offset, whence); if (__mes_debug ()) { - eputs ("fread fd="); eputs (itoa ((int)stream)); - eputs (" =>"); eputs (itoa (pos)); eputs ("\n"); + eputs ("fread fd="); + eputs (itoa ((int) stream)); + eputs (" =>"); + eputs (itoa (pos)); + eputs ("\n"); } if (pos >= 0) return 0; diff --git a/lib/stdio/ftell.c b/lib/stdio/ftell.c index 4d1fab04..8bdac53a 100644 --- a/lib/stdio/ftell.c +++ b/lib/stdio/ftell.c @@ -21,7 +21,7 @@ #include long -ftell (FILE *stream) +ftell (FILE * stream) { - return lseek ((int)stream, 0, SEEK_CUR); + return lseek ((int) stream, 0, SEEK_CUR); } diff --git a/lib/stdio/fwrite.c b/lib/stdio/fwrite.c index 533f3fd3..74487758 100644 --- a/lib/stdio/fwrite.c +++ b/lib/stdio/fwrite.c @@ -22,24 +22,29 @@ #include size_t -fwrite (void const *data, size_t size, size_t count, FILE *stream) +fwrite (void const *data, size_t size, size_t count, FILE * stream) { if (__mes_debug () > 1) { - eputs ("fwrite "); eputs (itoa ((int)stream)); - eputs (" "); eputs (itoa (size)); eputs ("\n"); + eputs ("fwrite "); + eputs (itoa ((int) stream)); + eputs (" "); + eputs (itoa (size)); + eputs ("\n"); } - if (! size || !count) + if (!size || !count) return 0; - int bytes = write ((int)stream, data, size * count); + int bytes = write ((int) stream, data, size * count); if (__mes_debug () > 2) { - eputs (" => "); eputs (itoa (bytes)); eputs ("\n"); + eputs (" => "); + eputs (itoa (bytes)); + eputs ("\n"); } if (bytes > 0) - return bytes/size; + return bytes / size; return 0; } diff --git a/lib/stdio/getc.c b/lib/stdio/getc.c index c32ff7a1..25774aa2 100644 --- a/lib/stdio/getc.c +++ b/lib/stdio/getc.c @@ -21,7 +21,7 @@ #include int -getc (FILE *stream) +getc (FILE * stream) { - return fdgetc ((long)stream); + return fdgetc ((long) stream); } diff --git a/lib/stdio/printf.c b/lib/stdio/printf.c index 95ad3d4e..879c9a64 100644 --- a/lib/stdio/printf.c +++ b/lib/stdio/printf.c @@ -22,7 +22,7 @@ #include int -printf (char const* format, ...) +printf (char const *format, ...) { va_list ap; int r; diff --git a/lib/stdio/putc.c b/lib/stdio/putc.c index 4c585767..1cc2ed28 100644 --- a/lib/stdio/putc.c +++ b/lib/stdio/putc.c @@ -21,7 +21,7 @@ #include int -putc (int c, FILE* stream) +putc (int c, FILE * stream) { - return fdputc (c, (long)stream); + return fdputc (c, (long) stream); } diff --git a/lib/stdio/putchar.c b/lib/stdio/putchar.c index 602e430c..7bd5ef63 100644 --- a/lib/stdio/putchar.c +++ b/lib/stdio/putchar.c @@ -23,6 +23,6 @@ int putchar (int c) { - write (STDOUT, (char*)&c, 1); + write (STDOUT, (char *) &c, 1); return 0; } diff --git a/lib/stdio/snprintf.c b/lib/stdio/snprintf.c index 8afb1fc2..f62da341 100644 --- a/lib/stdio/snprintf.c +++ b/lib/stdio/snprintf.c @@ -22,7 +22,7 @@ #include int -snprintf (char *str, size_t size, char const *format, ...) +snprintf (char *str, size_t size, char const *format, ...) { va_list ap; int r; diff --git a/lib/stdio/sprintf.c b/lib/stdio/sprintf.c index 5edf9306..6c130b15 100644 --- a/lib/stdio/sprintf.c +++ b/lib/stdio/sprintf.c @@ -22,7 +22,7 @@ #include int -sprintf (char *str, char const* format, ...) +sprintf (char *str, char const *format, ...) { va_list ap; int r; diff --git a/lib/stdio/ungetc.c b/lib/stdio/ungetc.c index a107a9f6..89109fc8 100644 --- a/lib/stdio/ungetc.c +++ b/lib/stdio/ungetc.c @@ -21,7 +21,7 @@ #include int -ungetc (int c, FILE *stream) +ungetc (int c, FILE * stream) { - return fdungetc (c, (long)stream); + return fdungetc (c, (long) stream); } diff --git a/lib/stdio/vfprintf.c b/lib/stdio/vfprintf.c index 2b251246..00abe7a6 100644 --- a/lib/stdio/vfprintf.c +++ b/lib/stdio/vfprintf.c @@ -24,9 +24,9 @@ #include int -vfprintf (FILE* f, char const* format, va_list ap) +vfprintf (FILE * f, char const *format, va_list ap) { - int fd = (long)f; + int fd = (long) f; char const *p = format; int count = 0; while (*p) @@ -107,9 +107,7 @@ vfprintf (FILE* f, char const* format, va_list ap) case 'X': { long d = va_arg (ap, long); - int base = c == 'o' ? 8 - : c == 'x' || c == 'X' ? 16 - : 10; + int base = c == 'o' ? 8 : c == 'x' || c == 'X' ? 16 : 10; char const *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X'); if (c == 'X') strupr (s); diff --git a/lib/stdio/vprintf.c b/lib/stdio/vprintf.c index 909d1fab..ff945943 100644 --- a/lib/stdio/vprintf.c +++ b/lib/stdio/vprintf.c @@ -22,7 +22,7 @@ #include int -vprintf (char const* format, va_list ap) +vprintf (char const *format, va_list ap) { return vfprintf (stdout, format, ap); } diff --git a/lib/stdio/vsnprintf.c b/lib/stdio/vsnprintf.c index 2021227e..beec362a 100644 --- a/lib/stdio/vsnprintf.c +++ b/lib/stdio/vsnprintf.c @@ -23,7 +23,7 @@ #include int -vsnprintf (char *str, size_t size, char const* format, va_list ap) +vsnprintf (char *str, size_t size, char const *format, va_list ap) { char const *p = format; int count = 0; @@ -112,9 +112,7 @@ vsnprintf (char *str, size_t size, char const* format, va_list ap) case 'X': { long d = va_arg (ap, long); - int base = c == 'o' ? 8 - : c == 'x' || c == 'X' ? 16 - : 10; + int base = c == 'o' ? 8 : c == 'x' || c == 'X' ? 16 : 10; char const *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X'); if (c == 'X') strupr (s); diff --git a/lib/stdio/vsprintf.c b/lib/stdio/vsprintf.c index 8a65b0d6..caae3d65 100644 --- a/lib/stdio/vsprintf.c +++ b/lib/stdio/vsprintf.c @@ -22,7 +22,7 @@ #include int -vsprintf (char *str, char const* format, va_list ap) +vsprintf (char *str, char const *format, va_list ap) { return vsnprintf (str, LONG_MAX, format, ap); } diff --git a/lib/stdio/vsscanf.c b/lib/stdio/vsscanf.c index 23aa3053..10f874f2 100644 --- a/lib/stdio/vsscanf.c +++ b/lib/stdio/vsscanf.c @@ -49,7 +49,7 @@ vsscanf (char const *s, char const *template, va_list ap) } case 'c': { - char *c = va_arg (ap, char*); + char *c = va_arg (ap, char *); *c = *p++; count++; break; @@ -58,7 +58,7 @@ vsscanf (char const *s, char const *template, va_list ap) case 'i': case 'u': { - int *d = va_arg (ap, int*); + int *d = va_arg (ap, int *); *d = abtol (&p, 10); count++; break; diff --git a/lib/stdlib/alloca.c b/lib/stdlib/alloca.c index dee539d7..5c8bf008 100644 --- a/lib/stdlib/alloca.c +++ b/lib/stdlib/alloca.c @@ -32,15 +32,15 @@ union alloca_header { - char align[ALIGN_SIZE]; /* To force sizeof(union alloca_header). */ + char align[ALIGN_SIZE]; /* To force sizeof(union alloca_header). */ struct - { - union alloca_header *next; /* For chaining headers. */ - char *deep; /* For stack depth measure. */ - } h; + { + union alloca_header *next; /* For chaining headers. */ + char *deep; /* For stack depth measure. */ + } h; }; -static union alloca_header *last_alloca_header = NULL; /* -> last alloca header. */ +static union alloca_header *last_alloca_header = NULL; /* -> last alloca header. */ /* Return a void * to at least SIZE bytes of storage, which will be automatically reclaimed upon exit from @@ -52,43 +52,42 @@ static union alloca_header *last_alloca_header = NULL; /* -> last alloca header. void * alloca (size_t size) { - char probe; /* Probes stack depth: */ + char probe; /* Probes stack depth: */ char *depth = ADDRESS_FUNCTION (probe); /* Reclaim garbage, defined as all alloca'd storage that was allocated from deeper in the stack than currently. */ { - union alloca_header *hp; /* Traverses linked list. */ + union alloca_header *hp; /* Traverses linked list. */ for (hp = last_alloca_header; hp != NULL;) - if ((STACK_DIR > 0 && hp->h.deep > depth) - || (STACK_DIR < 0 && hp->h.deep < depth)) - { - union alloca_header *np = hp->h.next; + if ((STACK_DIR > 0 && hp->h.deep > depth) || (STACK_DIR < 0 && hp->h.deep < depth)) + { + union alloca_header *np = hp->h.next; - free ((void *) hp); /* Collect garbage. */ + free ((void *) hp); /* Collect garbage. */ - hp = np; /* -> next header. */ - } + hp = np; /* -> next header. */ + } else - break; /* Rest are not deeper. */ + break; /* Rest are not deeper. */ - last_alloca_header = hp; /* -> last valid storage. */ + last_alloca_header = hp; /* -> last valid storage. */ } if (size == 0) - return NULL; /* No allocation required. */ + return NULL; /* No allocation required. */ /* Allocate combined header + user data storage. */ { - void * new = malloc (sizeof (union alloca_header) + size); + void *new = malloc (sizeof (union alloca_header) + size); /* Address of header. */ if (new == 0) - abort(); + abort (); ((union alloca_header *) new)->h.next = last_alloca_header; ((union alloca_header *) new)->h.deep = depth; diff --git a/lib/stdlib/mbstowcs.c b/lib/stdlib/mbstowcs.c index 9330f355..40dca931 100644 --- a/lib/stdlib/mbstowcs.c +++ b/lib/stdlib/mbstowcs.c @@ -24,8 +24,7 @@ typedef char wchar_t[]; size_t -mbstowcs (wchar_t *wstring, char const *string, - size_t size) +mbstowcs (wchar_t * wstring, char const *string, size_t size) { static int stub = 0; if (__mes_debug () && !stub) diff --git a/lib/stdlib/puts.c b/lib/stdlib/puts.c index d7ada8b7..fea5dff6 100644 --- a/lib/stdlib/puts.c +++ b/lib/stdlib/puts.c @@ -21,7 +21,7 @@ #include int -puts (char const* s) +puts (char const *s) { oputs (s); return oputs ("\n"); diff --git a/lib/stdlib/qsort.c b/lib/stdlib/qsort.c index 237f121d..4f3e61cb 100644 --- a/lib/stdlib/qsort.c +++ b/lib/stdlib/qsort.c @@ -31,20 +31,20 @@ qswap (void *a, void *b, size_t size) } size_t -qpart (void *base, size_t count, size_t size, int (*compare)(void const *, void const *)) +qpart (void *base, size_t count, size_t size, int (*compare) (void const *, void const *)) { - void* p = base + count*size; + void *p = base + count * size; size_t i = 0; for (size_t j = 0; j < count; j++) { - int c = compare (base+j*size, p); + int c = compare (base + j * size, p); if (c < 0) { -#if 1 //__x86_64__ - qswap (base+i*size, base+j*size, size); +#if 1 //__x86_64__ + qswap (base + i * size, base + j * size, size); #else - int p1 = base+i*size; - int p2 = base+j*size; + int p1 = base + i * size; + int p2 = base + j * size; qswap (p1, p2, size); #endif i++; @@ -52,23 +52,23 @@ qpart (void *base, size_t count, size_t size, int (*compare)(void const *, void else if (c == 0) i++; } - if (compare (base+count*size, base+i*size) < 0) - qswap (base+i*size, base+count*size, size); + if (compare (base + count * size, base + i * size) < 0) + qswap (base + i * size, base + count * size, size); return i; } void -qsort (void *base, size_t count, size_t size, int (*compare)(void const *, void const *)) +qsort (void *base, size_t count, size_t size, int (*compare) (void const *, void const *)) { if (count > 1) { - int p = qpart (base, count-1, size, compare); + int p = qpart (base, count - 1, size, compare); qsort (base, p, size, compare); -#if 1 //__x86_64__ - qsort (base+p*size, count-p, size, compare); +#if 1 //__x86_64__ + qsort (base + p * size, count - p, size, compare); #else - int p1 = base+p*size; - int p2 = count-p; + int p1 = base + p * size; + int p2 = count - p; qsort (p1, p2, size, compare); #endif } diff --git a/lib/string/argz-count.c b/lib/string/argz-count.c index 2cd01752..b5e8e6cd 100644 --- a/lib/string/argz-count.c +++ b/lib/string/argz-count.c @@ -33,12 +33,12 @@ __argz_count (const char *argz, size_t len) size_t count = 0; while (len > 0) { - size_t part_len = strlen(argz); + size_t part_len = strlen (argz); argz += part_len + 1; len -= part_len + 1; count++; } return count; } -libc_hidden_def (__argz_count) -weak_alias (__argz_count, argz_count) + +libc_hidden_def (__argz_count) weak_alias (__argz_count, argz_count) diff --git a/lib/string/argz-extract.c b/lib/string/argz-extract.c index 163a2750..bbf6292c 100644 --- a/lib/string/argz-extract.c +++ b/lib/string/argz-extract.c @@ -39,4 +39,5 @@ __argz_extract (const char *argz, size_t len, char **argv) } *argv = 0; } + weak_alias (__argz_extract, argz_extract) diff --git a/lib/string/memcpy.c b/lib/string/memcpy.c index afdfca90..307f6433 100644 --- a/lib/string/memcpy.c +++ b/lib/string/memcpy.c @@ -21,8 +21,8 @@ void * memcpy (void *dest, void const *src, size_t n) { - char* p = dest; - char const* q = src; + char *p = dest; + char const *q = src; while (n--) *p++ = *q++; return dest; diff --git a/lib/string/memmem.c b/lib/string/memmem.c index a4883e7a..d65e3b17 100644 --- a/lib/string/memmem.c +++ b/lib/string/memmem.c @@ -28,8 +28,7 @@ Manual v1.15, but it is with /usr/include/string.h */ unsigned char * -_memmem (unsigned char const *haystack, int haystack_len, - unsigned char const *needle, int needle_len) +_memmem (unsigned char const *haystack, int haystack_len, unsigned char const *needle, int needle_len) { unsigned char const *end_haystack = haystack + haystack_len - needle_len + 1; unsigned char const *end_needle = needle + needle_len; @@ -53,10 +52,9 @@ _memmem (unsigned char const *haystack, int haystack_len, } void * -memmem (void const *haystack, int haystack_len, - void const *needle, int needle_len) +memmem (void const *haystack, int haystack_len, void const *needle, int needle_len) { - unsigned char const *haystack_byte_c = (unsigned char const *)haystack; - unsigned char const *needle_byte_c = (unsigned char const *)needle; + unsigned char const *haystack_byte_c = (unsigned char const *) haystack; + unsigned char const *needle_byte_c = (unsigned char const *) needle; return _memmem (haystack_byte_c, haystack_len, needle_byte_c, needle_len); } diff --git a/lib/string/memmove.c b/lib/string/memmove.c index 3149d696..37b8661d 100644 --- a/lib/string/memmove.c +++ b/lib/string/memmove.c @@ -26,7 +26,7 @@ memmove (void *dest, void const *src, size_t n) if (dest < src) return memcpy (dest, src, n); char *p = dest + n; - char const *q = src +n; + char const *q = src + n; while (n--) *--p = *--q; return dest; diff --git a/lib/string/strcmp.c b/lib/string/strcmp.c index 12e39233..40c43111 100644 --- a/lib/string/strcmp.c +++ b/lib/string/strcmp.c @@ -21,7 +21,7 @@ #include int -strcmp (char const* a, char const* b) +strcmp (char const *a, char const *b) { while (*a && *b && *a == *b) { diff --git a/lib/string/strdup.c b/lib/string/strdup.c index 5a81323e..e87b8ee1 100644 --- a/lib/string/strdup.c +++ b/lib/string/strdup.c @@ -24,7 +24,7 @@ char * strdup (char const *s) { size_t length = strlen (s) + 1; - char *p = (char*)malloc (length); + char *p = (char *) malloc (length); if (p) return memcpy (p, s, length); return 0; diff --git a/lib/string/strerror.c b/lib/string/strerror.c index d409482a..c0c31c65 100644 --- a/lib/string/strerror.c +++ b/lib/string/strerror.c @@ -20,49 +20,48 @@ #include -char *sys_errlist[] = - { - "error 00", - "error 01", - "error 02", - "error 03", - "error 04", - "error 05", - "error 06", - "error 07", - "error 08", - "error 09", - "error 10", - "error 11", - "error 12", - "error 13", - "error 14", - "error 15", - "error 16", - "error 17", - "error 18", - "error 19", - "error 20", - "error 21", - "error 22", - "error 23", - "error 24", - "error 25", - "error 26", - "error 27", - "error 28", - "error 29", - "error 30", - "error 31", - "error 32", - "error 33", - "error 34", - "error 35", - "error 36", - "error 37", - "error 38", - "error 39", - }; +char *sys_errlist[] = { + "error 00", + "error 01", + "error 02", + "error 03", + "error 04", + "error 05", + "error 06", + "error 07", + "error 08", + "error 09", + "error 10", + "error 11", + "error 12", + "error 13", + "error 14", + "error 15", + "error 16", + "error 17", + "error 18", + "error 19", + "error 20", + "error 21", + "error 22", + "error 23", + "error 24", + "error 25", + "error 26", + "error 27", + "error 28", + "error 29", + "error 30", + "error 31", + "error 32", + "error 33", + "error 34", + "error 35", + "error 36", + "error 37", + "error 38", + "error 39", +}; int sys_nerr = 39; @@ -71,7 +70,9 @@ strerror (int errnum) { if (__mes_debug ()) { - eputs ("strerror errnum="); eputs (itoa (errnum)); eputs ("\n"); + eputs ("strerror errnum="); + eputs (itoa (errnum)); + eputs ("\n"); } if (errnum > 0 && errnum <= sys_nerr) return sys_errlist[errnum]; diff --git a/lib/string/strlen.c b/lib/string/strlen.c index 5d9446b4..3ce75ef7 100644 --- a/lib/string/strlen.c +++ b/lib/string/strlen.c @@ -21,7 +21,7 @@ #include size_t -strlen (char const* s) +strlen (char const *s) { int i = 0; while (s[i]) diff --git a/lib/string/strncat.c b/lib/string/strncat.c index ff3ba121..9683f91e 100644 --- a/lib/string/strncat.c +++ b/lib/string/strncat.c @@ -25,7 +25,7 @@ strncat (char *to, char const *from, size_t size) { if (size == 0) return to; - char *p = strchr (to , '\0'); + char *p = strchr (to, '\0'); while (*from && size-- > 0) *p++ = *from++; *p = 0; diff --git a/lib/string/strncmp.c b/lib/string/strncmp.c index 81ffd106..cfc96957 100644 --- a/lib/string/strncmp.c +++ b/lib/string/strncmp.c @@ -21,7 +21,7 @@ #include int -strncmp (char const* a, char const* b, size_t size) +strncmp (char const *a, char const *b, size_t size) { if (!size) return 0; diff --git a/lib/string/strpbrk.c b/lib/string/strpbrk.c index a79a8122..92b0cdb8 100644 --- a/lib/string/strpbrk.c +++ b/lib/string/strpbrk.c @@ -21,7 +21,7 @@ #include char * -strpbrk (char const *string, char const* stopset) +strpbrk (char const *string, char const *stopset) { char *p = string; while (*p) diff --git a/lib/stub/fpurge.c b/lib/stub/fpurge.c index 2e923da4..0b883a25 100644 --- a/lib/stub/fpurge.c +++ b/lib/stub/fpurge.c @@ -22,7 +22,7 @@ #include int -fpurge (FILE *stream) +fpurge (FILE * stream) { static int stub = 0; if (__mes_debug () && !stub) diff --git a/lib/stub/freadahead.c b/lib/stub/freadahead.c index 0c3f9969..0364f2e1 100644 --- a/lib/stub/freadahead.c +++ b/lib/stub/freadahead.c @@ -22,7 +22,7 @@ #include size_t -freadahead (FILE *fp) +freadahead (FILE * fp) { static int stub = 0; if (__mes_debug () && !stub) diff --git a/lib/stub/setvbuf.c b/lib/stub/setvbuf.c index 66751b91..801856ff 100644 --- a/lib/stub/setvbuf.c +++ b/lib/stub/setvbuf.c @@ -22,7 +22,7 @@ #include int -setvbuf (FILE *stream, char *buf, int mode, size_t size) +setvbuf (FILE * stream, char *buf, int mode, size_t size) { static int stub = 0; if (__mes_debug () && !stub) diff --git a/lib/stub/sigaddset.c b/lib/stub/sigaddset.c index 3259a054..94e8e7d0 100644 --- a/lib/stub/sigaddset.c +++ b/lib/stub/sigaddset.c @@ -22,7 +22,7 @@ #include int -sigaddset (sigset_t *set, int signum) +sigaddset (sigset_t * set, int signum) { return 0; } diff --git a/lib/stub/sigdelset.c b/lib/stub/sigdelset.c index 78312e0e..a5f3b076 100644 --- a/lib/stub/sigdelset.c +++ b/lib/stub/sigdelset.c @@ -22,7 +22,7 @@ #include int -sigdelset (sigset_t *set, int signum) +sigdelset (sigset_t * set, int signum) { return 0; } diff --git a/lib/stub/sigemptyset.c b/lib/stub/sigemptyset.c index de7f2a29..a16ca7de 100644 --- a/lib/stub/sigemptyset.c +++ b/lib/stub/sigemptyset.c @@ -22,7 +22,7 @@ #include int -sigemptyset (sigset_t *set) +sigemptyset (sigset_t * set) { return 0; } diff --git a/lib/stub/strftime.c b/lib/stub/strftime.c index 02b16cc6..34ecb5d7 100644 --- a/lib/stub/strftime.c +++ b/lib/stub/strftime.c @@ -21,8 +21,7 @@ #include size_t -strftime (char *s, size_t size, char const *template, - struct tm const *brokentime) +strftime (char *s, size_t size, char const *template, struct tm const *brokentime) { static int stub = 0; if (__mes_debug () && !stub) diff --git a/lib/stub/ttyname.c b/lib/stub/ttyname.c index 12359387..018dbd2b 100644 --- a/lib/stub/ttyname.c +++ b/lib/stub/ttyname.c @@ -30,6 +30,6 @@ ttyname (int filedes) stub = 1; errno = 0; if (isatty (filedes)) - return "/dev/tty0"; + return "/dev/tty0"; return 0; } diff --git a/lib/tests/assert/50-assert.c b/lib/tests/assert/50-assert.c index 7b5c7a98..6702ab10 100644 --- a/lib/tests/assert/50-assert.c +++ b/lib/tests/assert/50-assert.c @@ -32,7 +32,7 @@ main () assert (1); puts ("t: assert (f==0) ?\n"); - assert (f==0); + assert (f == 0); return 0; } diff --git a/lib/tests/dirent/90-readdir.c b/lib/tests/dirent/90-readdir.c index 3e89e1d5..602b6176 100644 --- a/lib/tests/dirent/90-readdir.c +++ b/lib/tests/dirent/90-readdir.c @@ -26,9 +26,9 @@ #include int -qsort_strcmp (void const* a, void const* b) +qsort_strcmp (void const *a, void const *b) { - return strcmp (*((char**) a), *((char**) b)); + return strcmp (*((char **) a), *((char **) b)); } int @@ -55,7 +55,7 @@ main () return 6; int i = 0; - char* list[6] = {0}; + char *list[6] = { 0 }; struct dirent *entry = readdir (d); if (!entry) return 7; @@ -96,10 +96,11 @@ main () return 12; oputs ("\nls:\n"); - qsort (list, 5, sizeof (char*), qsort_strcmp); + qsort (list, 5, sizeof (char *), qsort_strcmp); for (int i = 0; i < 5; i++) { - oputs (list[i]); oputs ("\n"); + oputs (list[i]); + oputs ("\n"); } if (strcmp (list[0], ".")) diff --git a/lib/tests/io/90-stat.c b/lib/tests/io/90-stat.c index cc166486..a2d49830 100644 --- a/lib/tests/io/90-stat.c +++ b/lib/tests/io/90-stat.c @@ -29,24 +29,24 @@ struct stat { - unsigned long st_dev; - unsigned long st_ino; + 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; + 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 @@ -74,27 +74,55 @@ main () 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_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_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="); + 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="); + 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="); + 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"); + eputs ("size:"); + eputs (itoa (sizeof (struct stat))); + eputs ("\n"); return 0; } diff --git a/lib/tests/mes/50-itoa.c b/lib/tests/mes/50-itoa.c index bd4a1be1..c8471400 100644 --- a/lib/tests/mes/50-itoa.c +++ b/lib/tests/mes/50-itoa.c @@ -28,7 +28,9 @@ main () oputs ("\n"); oputs ("t: itoa (33) == \"33\"\n"); - oputs ("=>"); oputs (itoa (33)); oputs ("\n"); + oputs ("=>"); + oputs (itoa (33)); + oputs ("\n"); if (strcmp (itoa (33), "33")) return 1; diff --git a/lib/tests/setjmp/80-setjmp.c b/lib/tests/setjmp/80-setjmp.c index 64228846..1694ab21 100644 --- a/lib/tests/setjmp/80-setjmp.c +++ b/lib/tests/setjmp/80-setjmp.c @@ -27,12 +27,12 @@ int foo; void -second() +second () { if (foo++) exit (1); - oputs ("second\n"); // prints - longjmp (buf, 1); // jumps back to where setjmp was called - making setjmp now return 1 + oputs ("second\n"); // prints + longjmp (buf, 1); // jumps back to where setjmp was called - making setjmp now return 1 exit (1); } @@ -40,7 +40,7 @@ void first () { second (); - oputs ("first\n"); // does not print + oputs ("first\n"); // does not print exit (2); } @@ -48,10 +48,10 @@ int main () { if (!setjmp (buf)) - first (); // when executed, setjmp returned 0 - else // when longjmp jumps back, setjmp returns 1 + first (); // when executed, setjmp returned 0 + else // when longjmp jumps back, setjmp returns 1 { - oputs ("main\n"); // prints + oputs ("main\n"); // prints return 0; } diff --git a/lib/tests/signal/90-signal.c b/lib/tests/signal/90-signal.c index fb6e3a7f..710b3d0a 100644 --- a/lib/tests/signal/90-signal.c +++ b/lib/tests/signal/90-signal.c @@ -30,21 +30,25 @@ void handler (int signum) { #if __MESC__ && __x86_64__ - asm ("mov____%rdi,0x8(%rbp) !0x10"); // FIXME: AMDCC + asm ("mov____%rdi,0x8(%rbp) !0x10"); // FIXME: AMDCC #endif - eputs ("handle:"); eputs (itoa (signum)); eputs ("\n"); + eputs ("handle:"); + eputs (itoa (signum)); + eputs ("\n"); if (signum != SIGALRM) exit (66); g_alarm_handled_p = 1; - #if __x86_64__ +#if __x86_64__ exit (0); - #endif +#endif } int main (void) { - eputs ("pid_t="); eputs (itoa (sizeof (pid_t))); eputs ("\n"); + eputs ("pid_t="); + eputs (itoa (sizeof (pid_t))); + eputs ("\n"); signal (SIGALRM, handler); kill (getpid (), SIGALRM); if (!g_alarm_handled_p) diff --git a/lib/tests/stdio/70-printf-simple.c b/lib/tests/stdio/70-printf-simple.c index aba3bae5..b2e694b1 100644 --- a/lib/tests/stdio/70-printf-simple.c +++ b/lib/tests/stdio/70-printf-simple.c @@ -54,7 +54,9 @@ main () return 4; sprintf (buf, "%u", -1); - eputs ("buf="); eputs (buf); eputs ("\n"); + eputs ("buf="); + eputs (buf); + eputs ("\n"); #if __i386__ if (strcmp (buf, "4294967295")) @@ -65,17 +67,20 @@ main () #endif sprintf (buf, ">>%o<<\n", 12); - eputs ("buf="); eputs (buf); + eputs ("buf="); + eputs (buf); if (strcmp (buf, ">>14<<\n")) return 7; sprintf (buf, ">>%x<<\n", 12); - eputs ("buf="); eputs (buf); + eputs ("buf="); + eputs (buf); if (strcmp (buf, ">>c<<\n")) return 8; sprintf (buf, ">>%X<<\n", 12); - eputs ("buf="); eputs (buf); + eputs ("buf="); + eputs (buf); if (strcmp (buf, ">>C<<\n")) return 9; diff --git a/lib/tests/stdio/70-printf.c b/lib/tests/stdio/70-printf.c index 43a482b7..aa6687cf 100644 --- a/lib/tests/stdio/70-printf.c +++ b/lib/tests/stdio/70-printf.c @@ -53,22 +53,26 @@ main () return 3; sprintf (buf, ">%3d<", 11); - eputs (buf); eputs ("\n"); + eputs (buf); + eputs ("\n"); if (strcmp (buf, "> 11<")) return 4; sprintf (buf, ">%03d<", 22); - eputs (buf); eputs ("\n"); + eputs (buf); + eputs ("\n"); if (strcmp (buf, ">022<")) return 5; sprintf (buf, ">%-10d<", 33); - eputs (buf); eputs ("\n"); + eputs (buf); + eputs ("\n"); if (strcmp (buf, ">33 <")) return 6; sprintf (buf, ">%0d<", 44); - eputs (buf); eputs ("\n"); + eputs (buf); + eputs ("\n"); if (strcmp (buf, ">44<")) return 7; @@ -80,12 +84,16 @@ main () printf (">>%-*s<<\n", 10, "baz"); sprintf (buf, "%ld", 42); - eputs ("buf="); eputs (buf); eputs ("\n"); + eputs ("buf="); + eputs (buf); + eputs ("\n"); if (strcmp (buf, "42")) return 8; sprintf (buf, "%u", -1); - eputs ("buf="); eputs (buf); eputs ("\n"); + eputs ("buf="); + eputs (buf); + eputs ("\n"); #if __i386__ if (strcmp (buf, "4294967295")) @@ -96,52 +104,62 @@ main () #endif sprintf (buf, ">>%.5s<<\n", "hello, world"); - eputs ("buf="); eputs (buf); + eputs ("buf="); + eputs (buf); if (strcmp (buf, ">>hello<<\n")) return 10; sprintf (buf, ">>%.*s<<\n", 5, "hello, world"); - eputs ("buf="); eputs (buf); + eputs ("buf="); + eputs (buf); if (strcmp (buf, ">>hello<<\n")) return 11; sprintf (buf, ">>%.*s<<\n", 20, "hello, world"); - eputs ("buf="); eputs (buf); + eputs ("buf="); + eputs (buf); if (strcmp (buf, ">>hello, world<<\n")) return 12; sprintf (buf, ">>%.*s<<\n", 10, "foo"); - eputs ("buf="); eputs (buf); + eputs ("buf="); + eputs (buf); if (strcmp (buf, ">>foo<<\n")) return 13; sprintf (buf, ">>%*s<<\n", 10, "bar"); - eputs ("buf="); eputs (buf); + eputs ("buf="); + eputs (buf); if (strcmp (buf, ">> bar<<\n")) return 14; sprintf (buf, ">>%-*s<<\n", 10, "baz"); - eputs ("buf="); eputs (buf); + eputs ("buf="); + eputs (buf); if (strcmp (buf, ">>baz <<\n")) return 15; sprintf (buf, ">>%ld<<\n", 12); - eputs ("buf="); eputs (buf); + eputs ("buf="); + eputs (buf); if (strcmp (buf, ">>12<<\n")) return 16; sprintf (buf, ">>%o<<\n", 12); - eputs ("buf="); eputs (buf); + eputs ("buf="); + eputs (buf); if (strcmp (buf, ">>14<<\n")) return 17; sprintf (buf, ">>%x<<\n", 12); - eputs ("buf="); eputs (buf); + eputs ("buf="); + eputs (buf); if (strcmp (buf, ">>c<<\n")) return 18; sprintf (buf, ">>%X<<\n", 12); - eputs ("buf="); eputs (buf); + eputs ("buf="); + eputs (buf); if (strcmp (buf, ">>C<<\n")) return 19; @@ -153,7 +171,9 @@ main () #endif sprintf (buf, "foo%nbar\n", &n); - eputs ("buf="); eputs (buf); eputs ("\n"); + eputs ("buf="); + eputs (buf); + eputs ("\n"); if (strcmp (buf, "foobar\n")) return 21; if (n != 3) @@ -164,7 +184,9 @@ main () #endif sprintf (buf, "%12.8d\n", 12345); - eputs ("buf="); eputs (buf); eputs ("\n"); + eputs ("buf="); + eputs (buf); + eputs ("\n"); if (strcmp (buf, " 00012345\n")) return 23; diff --git a/lib/tests/stdio/90-fopen-append.c b/lib/tests/stdio/90-fopen-append.c index 7226578f..93182941 100644 --- a/lib/tests/stdio/90-fopen-append.c +++ b/lib/tests/stdio/90-fopen-append.c @@ -25,26 +25,29 @@ #include #include -int main() +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); + 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); } diff --git a/lib/tests/stdio/90-fopen.c b/lib/tests/stdio/90-fopen.c index b304c9b4..59d8db1b 100644 --- a/lib/tests/stdio/90-fopen.c +++ b/lib/tests/stdio/90-fopen.c @@ -27,7 +27,7 @@ #include int -dump (char const *name, char const* contents) +dump (char const *name, char const *contents) { unlink (name); FILE *f = fopen (name, "w"); @@ -40,7 +40,7 @@ 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 *end = "That's all folks!\n"; char *tmp = "foo"; @@ -53,7 +53,9 @@ main () char buf[80]; memset (buf, 0, sizeof (buf)); fread (buf, strlen (line), 1, t); - eputs ("buf="); eputs (buf); eputs ("\n"); + eputs ("buf="); + eputs (buf); + eputs ("\n"); if (strcmp (buf, line)) return 2; @@ -62,7 +64,9 @@ main () fseek (t, 0, SEEK_SET); memset (buf, 0, sizeof (buf)); fread (buf, strlen (line), 1, t); - eputs ("buf="); eputs (buf); eputs ("\n"); + eputs ("buf="); + eputs (buf); + eputs ("\n"); if (strcmp (buf, line)) return 3; @@ -76,7 +80,9 @@ main () fseek (t, 0, SEEK_SET); memset (buf, 0, sizeof (buf)); fread (buf, strlen (end), 1, t); - eputs ("buf="); eputs (buf); eputs ("\n"); + eputs ("buf="); + eputs (buf); + eputs ("\n"); if (strcmp (buf, end)) return 5; @@ -98,7 +104,9 @@ main () fseek (t, 0, SEEK_SET); memset (buf, 0, sizeof (buf)); fread (buf, strlen (line), 1, t); - eputs ("buf="); eputs (buf); eputs ("\n"); + eputs ("buf="); + eputs (buf); + eputs ("\n"); if (strcmp (buf, line)) return 8; @@ -106,7 +114,9 @@ main () fseek (t, 0, SEEK_SET); fread (buf, strlen (line), 1, t); - eputs ("buf="); eputs (buf); eputs ("\n"); + eputs ("buf="); + eputs (buf); + eputs ("\n"); if (strcmp (buf, line)) return 9; diff --git a/lib/tests/stdio/90-fread-fwrite.c b/lib/tests/stdio/90-fread-fwrite.c index dfd507e2..cc079ead 100644 --- a/lib/tests/stdio/90-fread-fwrite.c +++ b/lib/tests/stdio/90-fread-fwrite.c @@ -47,7 +47,7 @@ main () int size = ftell (t); fprintf (stderr, " size=>%d\n", size); fseek (t, 0, SEEK_SET); - char *p = (char*)malloc (size + 1); + char *p = (char *) malloc (size + 1); fread (p, size, 1, t); fwrite (p, size, 1, n); @@ -59,7 +59,9 @@ main () char buf[200]; fflush (n); fread (buf, strlen (header_plus_data), 1, test); - eputs ("buf="); eputs (buf); eputs ("\n"); + eputs ("buf="); + eputs (buf); + eputs ("\n"); if (strcmp (buf, header_plus_data)) return 1; diff --git a/lib/tests/stdio/90-fseek.c b/lib/tests/stdio/90-fseek.c index 6e4318d0..b776c1dd 100644 --- a/lib/tests/stdio/90-fseek.c +++ b/lib/tests/stdio/90-fseek.c @@ -30,7 +30,7 @@ main () int fd = open ("COPYING", 0); if (fd <= 0) return 1; - FILE* f = fdopen (fd, "r"); + FILE *f = fdopen (fd, "r"); int r = fseek (f, 0, SEEK_CUR); if (r != 0) return 2; @@ -43,14 +43,17 @@ main () return 4; pos = ftell (f); - eputs ("size="); eputs (itoa (pos)); eputs ("\n"); + 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); + eputs ("buf:"); + eputs (buf); if (strcmp (buf, " GNU GENERAL PUBLIC LICENSE\n")) return 6; diff --git a/lib/tests/stdlib/50-malloc.c b/lib/tests/stdlib/50-malloc.c index c3af98f4..f0caf755 100644 --- a/lib/tests/stdlib/50-malloc.c +++ b/lib/tests/stdlib/50-malloc.c @@ -39,14 +39,14 @@ main (int argc, char *argv[]) oputs (itoa (p)); oputs ("\n"); int i; - for (i = 0; i < size; i=i+1) + 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) + for (i = 0; i < size; i = i + 1) { oputs (itoa (i)); oputs (": "); diff --git a/lib/tests/stdlib/70-strtoull.c b/lib/tests/stdlib/70-strtoull.c index bc88e8ae..644a472e 100644 --- a/lib/tests/stdlib/70-strtoull.c +++ b/lib/tests/stdlib/70-strtoull.c @@ -29,15 +29,19 @@ main () { char *p = "42foo\n"; int n = abtol (&p, 0); - if (n != 42) return 1; + if (n != 42) + return 1; eputs (p); - if (strcmp (p, "foo\n")) return 2; + if (strcmp (p, "foo\n")) + return 2; p = "2azar\n"; - n = strtoull (p, (char**)&p, 16); - if (n != 42) return 3; + n = strtoull (p, (char **) &p, 16); + if (n != 42) + return 3; eputs (p); - if (strcmp (p, "zar\n")) return 4; + if (strcmp (p, "zar\n")) + return 4; return 0; } diff --git a/lib/tests/stdlib/80-qsort-dupes.c b/lib/tests/stdlib/80-qsort-dupes.c index 96934547..9912e7f4 100644 --- a/lib/tests/stdlib/80-qsort-dupes.c +++ b/lib/tests/stdlib/80-qsort-dupes.c @@ -22,20 +22,21 @@ #include int -qsort_strcmp (void const* a, void const* b) +qsort_strcmp (void const *a, void const *b) { - return strcmp (*((char**) a), *((char**) b)); + return strcmp (*((char **) a), *((char **) b)); } int main () { - char* list[3] = {"foo", "foo", 0 }; + char *list[3] = { "foo", "foo", 0 }; oputs ("\nls:\n"); - qsort (list, 2, sizeof (char*), qsort_strcmp); + qsort (list, 2, sizeof (char *), qsort_strcmp); for (int i = 0; i < 2; i++) { - oputs (list[i]); oputs ("\n"); + oputs (list[i]); + oputs ("\n"); } return 0; diff --git a/lib/tests/stdlib/80-qsort.c b/lib/tests/stdlib/80-qsort.c index 1cc0f4e8..c8be4cd2 100644 --- a/lib/tests/stdlib/80-qsort.c +++ b/lib/tests/stdlib/80-qsort.c @@ -25,21 +25,31 @@ int compare_int (void *a, void *b) { - eputs ("compare: "); eputs (itoa (*(int*)a)); eputs (" "); eputs (itoa (*(int*)a - *(int*)b)); eputs ("\n"); - return *(int*)a - *(int*)b; + eputs ("compare: "); + eputs (itoa (*(int *) a)); + 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}; + 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"); + eputs (itoa (i)); + eputs (":"); + eputs (itoa (lst[i])); + eputs ("\n"); } - if (lst[0] != -1) return 1; - if (lst[5] != 5) return 2; + if (lst[0] != -1) + return 1; + if (lst[5] != 5) + return 2; return 0; } diff --git a/lib/tests/stdlib/90-strtol.c b/lib/tests/stdlib/90-strtol.c index c1fefc68..318ce052 100644 --- a/lib/tests/stdlib/90-strtol.c +++ b/lib/tests/stdlib/90-strtol.c @@ -41,14 +41,18 @@ main () 4; char *p = "16"; - int n = strtol (p, (char **)&p, 0); - eputs ("p="); eputs (p); eputs ("\n"); + 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"); + n = strtol (p, (char **) &p, 0); + eputs ("p="); + eputs (p); + eputs ("\n"); if (*p != 0) return 5; diff --git a/lib/tests/string/30-strlen.c b/lib/tests/string/30-strlen.c index 09f798af..94b4c13a 100644 --- a/lib/tests/string/30-strlen.c +++ b/lib/tests/string/30-strlen.c @@ -26,7 +26,7 @@ main () if (strlen ("mes") == 3) goto ok; return 1; - ok: +ok: if (strlen ("mes") != 3) return 1; return 0; diff --git a/lib/tests/string/50-strcmp.c b/lib/tests/string/50-strcmp.c index 2240a006..bef3939c 100644 --- a/lib/tests/string/50-strcmp.c +++ b/lib/tests/string/50-strcmp.c @@ -37,14 +37,16 @@ main () return 2; oputs ("t: if (!strcmp (p, \"t.c\\n\"))\n"); - if (!strcmp (p, "mes")) goto ok1; + if (!strcmp (p, "mes")) + goto ok1; return 3; - ok1: +ok1: oputs ("t: if (strcmp (p, \"foo\"))\n"); - if (strcmp (p, "foo")) goto ok2; + if (strcmp (p, "foo")) + goto ok2; return 4; - ok2: +ok2: oputs ("t: itoa (33) == \"33\"\n"); if (strcmp (itoa (33), "33")) diff --git a/lib/tests/string/80-strncpy.c b/lib/tests/string/80-strncpy.c index 28ad9fa4..0e79e6c1 100644 --- a/lib/tests/string/80-strncpy.c +++ b/lib/tests/string/80-strncpy.c @@ -26,7 +26,7 @@ int main () { puts ("\n"); - char buf[10] = {0,0,0,0,0,0,0,0,0,0}; + char buf[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; strncpy (buf, "mesxxx", 3); puts ("buf:"); puts (buf); diff --git a/lib/tests/string/90-snprintf.c b/lib/tests/string/90-snprintf.c index 54410d14..06b1f89d 100644 --- a/lib/tests/string/90-snprintf.c +++ b/lib/tests/string/90-snprintf.c @@ -28,8 +28,10 @@ int main () { int n = snprintf (0, 0, "%s", "0123456"); - eputs ("***n="); eputs (itoa (n)); eputs ("\n"); - exit(n != 7); + eputs ("***n="); + eputs (itoa (n)); + eputs ("\n"); + exit (n != 7); /* if (n) */ /* return 1; */ diff --git a/lib/tests/string/90-strpbrk.c b/lib/tests/string/90-strpbrk.c index 68189fcc..5e1508fc 100644 --- a/lib/tests/string/90-strpbrk.c +++ b/lib/tests/string/90-strpbrk.c @@ -27,12 +27,14 @@ main () strcpy (buf, "foo"); strcat (buf, " bar"); - eputs (buf); eputs ("\n"); + eputs (buf); + eputs ("\n"); if (strcmp (buf, "foo bar")) - return 1; + return 1; strncat (buf, " bazzzz", 4); - eputs (buf); eputs ("\n"); + eputs (buf); + eputs ("\n"); if (strcmp (buf, "foo bar baz")) return 2; diff --git a/lib/x86-mes-gcc/setjmp.c b/lib/x86-mes-gcc/setjmp.c index 63ba1857..df65cf98 100644 --- a/lib/x86-mes-gcc/setjmp.c +++ b/lib/x86-mes-gcc/setjmp.c @@ -41,9 +41,9 @@ longjmp (jmp_buf env, int val) int setjmp (jmp_buf env) { - long *p = (long*)&env; + long *p = (long *) &env; env[0].__bp = p[-2]; env[0].__pc = p[-1]; - env[0].__sp = (long)&env; + env[0].__sp = (long) &env; return 0; } diff --git a/lib/x86-mes/setjmp.c b/lib/x86-mes/setjmp.c index db3dc4a3..8decb6e3 100644 --- a/lib/x86-mes/setjmp.c +++ b/lib/x86-mes/setjmp.c @@ -25,22 +25,22 @@ longjmp (jmp_buf env, int val) { val = val == 0 ? 1 : val; ///asm ("mov____0x8(%ebp),%eax !0x0c"); // val - asm ("mov____0x8(%ebp),%ebp !0x08"); // env* + asm ("mov____0x8(%ebp),%ebp !0x08"); // env* - asm ("mov____0x8(%ebp),%ebx !0x4"); // env.__pc - asm ("mov____0x8(%ebp),%esp !0x8"); // env.__sp - asm ("mov____0x8(%ebp),%ebp !0x0"); // env.__bp + asm ("mov____0x8(%ebp),%ebx !0x4"); // env.__pc + asm ("mov____0x8(%ebp),%esp !0x8"); // env.__sp + asm ("mov____0x8(%ebp),%ebp !0x0"); // env.__bp asm ("jmp____*%ebx"); // not reached exit (42); } int -setjmp (__jmp_buf *env) +setjmp (__jmp_buf * env) { - long *p = (long*)&env; + long *p = (long *) &env; env[0].__bp = p[-2]; env[0].__pc = p[-1]; - env[0].__sp = (long)&env; + env[0].__sp = (long) &env; return 0; } diff --git a/lib/x86_64-mes/setjmp.c b/lib/x86_64-mes/setjmp.c index 85a9ef0e..ebf5c1ce 100644 --- a/lib/x86_64-mes/setjmp.c +++ b/lib/x86_64-mes/setjmp.c @@ -23,18 +23,18 @@ void longjmp (jmp_buf env, int val) { -#if 0 //MES_CCAMD64 +#if 0 //MES_CCAMD64 asm ("push___%rdi"); #endif val = val == 0 ? 1 : val; -#if 0 //MES_CCAMD64 +#if 0 //MES_CCAMD64 asm ("pop____%rdi"); asm ("mov____0x8(%rdi),%rbp !0x00"); // env->__bp asm ("mov____0x8(%rdi),%rbx !0x08"); // env->__pc asm ("mov____0x8(%rdi),%rsp !0x10"); // env->__sp - asm ("jmp____*%rbx"); // jmp *PC + asm ("jmp____*%rbx"); // jmp *PC #else - asm ("mov____0x8(%rbp),%rbp !0x10"); // env* + asm ("mov____0x8(%rbp),%rbp !0x10"); // env* asm ("mov____0x8(%rbp),%rbx !0x08"); // env.__pc asm ("mov____0x8(%rbp),%rsp !0x10"); // env.__sp @@ -46,9 +46,9 @@ longjmp (jmp_buf env, int val) } int -setjmp (__jmp_buf *env) +setjmp (__jmp_buf * env) { -#if 0 //MES_CCAMD64 +#if 0 //MES_CCAMD64 asm ("mov____%rbp,%rax"); asm ("add____$i32,%rax %0x80"); @@ -62,10 +62,10 @@ setjmp (__jmp_buf *env) asm ("add____$i32,%rsi %0x10"); asm ("mov____%rsi,0x8(%rdi) !0x10"); #else - long *p = (long*)&env; + long *p = (long *) &env; env[0].__bp = p[-2]; env[0].__pc = p[-1]; - env[0].__sp = (long)&env; + env[0].__sp = (long) &env; #endif return 0; } diff --git a/scaffold/argv.c b/scaffold/argv.c index 43437a52..905772f7 100644 --- a/scaffold/argv.c +++ b/scaffold/argv.c @@ -22,7 +22,7 @@ #include int -strcmp (char const* a, char const* b) +strcmp (char const *a, char const *b) { while (*a && *b && *a == *b) { diff --git a/scaffold/cons-mes.c b/scaffold/cons-mes.c index 59532cdb..4e8b3c8a 100644 --- a/scaffold/cons-mes.c +++ b/scaffold/cons-mes.c @@ -38,20 +38,24 @@ int g_free = 0; SCM g_continuations = 0; SCM g_symbols = 0; SCM g_stack = 0; -SCM r0 = 0; // a/env -SCM r1 = 0; // param 1 -SCM r2 = 0; // save 2+load/dump -SCM r3 = 0; // continuation +SCM r0 = 0; // a/env +SCM r1 = 0; // param 1 +SCM r2 = 0; // save 2+load/dump +SCM r3 = 0; // continuation -enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART}; +enum type_t +{ TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, + TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART }; -struct scm { +struct scm +{ enum type_t type; SCM car; SCM cdr; }; -struct function { +struct function +{ int (*function) (void); int arity; char *name; @@ -60,7 +64,7 @@ struct function { #if __MESC__ struct scm *g_cells = arena; #else -struct scm *g_cells = (struct scm*)arena; +struct scm *g_cells = (struct scm *) arena; #endif #define cell_nil 1 @@ -101,26 +105,30 @@ int g_function = 0; SCM make_cell_ (SCM type, SCM car, SCM cdr); -struct function fun_make_cell_ = {&make_cell_,3,"core:make-cell"}; -struct scm scm_make_cell_ = {TFUNCTION,0,0}; +struct function fun_make_cell_ = { &make_cell_, 3, "core:make-cell" }; +struct scm scm_make_cell_ = { TFUNCTION, 0, 0 }; + //, "core:make-cell", 0}; SCM cell_make_cell_; SCM cons (SCM x, SCM y); -struct function fun_cons = {&cons,2,"cons"}; -struct scm scm_cons = {TFUNCTION,0,0}; +struct function fun_cons = { &cons, 2, "cons" }; +struct scm scm_cons = { TFUNCTION, 0, 0 }; + // "cons", 0}; SCM cell_cons; SCM car (SCM x); -struct function fun_car = {&car,1,"car"}; -struct scm scm_car = {TFUNCTION,0,0}; +struct function fun_car = { &car, 1, "car" }; +struct scm scm_car = { TFUNCTION, 0, 0 }; + // "car", 0}; SCM cell_car; SCM cdr (SCM x); -struct function fun_cdr = {&cdr,1,"cdr"}; -struct scm scm_cdr = {TFUNCTION,0,0}; +struct function fun_cdr = { &cdr, 1, "cdr" }; +struct scm scm_cdr = { TFUNCTION, 0, 0 }; + // "cdr", 0}; SCM cell_cdr; @@ -167,18 +175,25 @@ make_cell_ (SCM type, SCM car, SCM cdr) SCM x = alloc (1); assert (TYPE (type) == TNUMBER); TYPE (x) = VALUE (type); - if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER) { - if (car) CAR (x) = CAR (car); - if (cdr) CDR(x) = CDR(cdr); - } - else if (VALUE (type) == TFUNCTION) { - if (car) CAR (x) = car; - if (cdr) CDR(x) = CDR(cdr); - } - else { - CAR (x) = car; - CDR(x) = cdr; - } + if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER) + { + if (car) + CAR (x) = CAR (car); + if (cdr) + CDR (x) = CDR (cdr); + } + else if (VALUE (type) == TFUNCTION) + { + if (car) + CAR (x) = car; + if (cdr) + CDR (x) = CDR (cdr); + } + else + { + CAR (x) = car; + CDR (x) = cdr; + } return x; } @@ -212,7 +227,7 @@ car (SCM x) SCM cdr (SCM x) { - return CDR(x); + return CDR (x); } SCM @@ -226,7 +241,8 @@ gc_push_frame () SCM append2 (SCM x, SCM y) { - if (x == cell_nil) return y; + if (x == cell_nil) + return y; assert (TYPE (x) == TPAIR); return cons (car (x), append2 (cdr (x), y)); } @@ -238,19 +254,19 @@ pairlis (SCM x, SCM y, SCM a) return a; if (TYPE (x) != TPAIR) return cons (cons (x, y), a); - return cons (cons (car (x), car (y)), - pairlis (cdr (x), cdr (y), a)); + return cons (cons (car (x), car (y)), pairlis (cdr (x), cdr (y), a)); } SCM assq (SCM x, SCM a) { - while (a != cell_nil && x == CAAR (a)) a = CDR (a); + while (a != cell_nil && x == CAAR (a)) + a = CDR (a); return a != cell_nil ? car (a) : cell_f; } SCM -push_cc (SCM p1, SCM p2, SCM a, SCM c) ///((internal)) +push_cc (SCM p1, SCM p2, SCM a, SCM c) ///((internal)) { puts ("push cc\n"); SCM x = r3; @@ -263,40 +279,66 @@ push_cc (SCM p1, SCM p2, SCM a, SCM c) ///((internal)) return cell_unspecified; } -SCM caar (SCM x) {return car (car (x));} -SCM cadr (SCM x) {return car (cdr (x));} -SCM cdar (SCM x) {return cdr (car (x));} -SCM cddr (SCM x) {return cdr (cdr (x));} +SCM +caar (SCM x) +{ + return car (car (x)); +} + +SCM +cadr (SCM x) +{ + return car (cdr (x)); +} + +SCM +cdar (SCM x) +{ + return cdr (car (x)); +} + +SCM +cddr (SCM x) +{ + return cdr (cdr (x)); +} #if __GNUC__ //FIXME -SCM call (SCM,SCM); +SCM call (SCM, SCM); SCM gc_pop_frame (); #endif SCM eval_apply () { - eval_apply: +eval_apply: switch (r3) { - case cell_vm_apply: {goto apply;} - case cell_unspecified: {return r1;} + case cell_vm_apply: + { + goto apply; + } + case cell_unspecified: + { + return r1; + } } SCM x = cell_nil; SCM y = cell_nil; - apply: +apply: switch (TYPE (car (r1))) { - case TFUNCTION: { - puts ("apply.function\n"); - r1 = call (car (r1), cdr (r1)); - goto vm_return; + case TFUNCTION: + { + puts ("apply.function\n"); + r1 = call (car (r1), cdr (r1)); + goto vm_return; + } } - } - vm_return: +vm_return: x = r1; gc_pop_frame (); r1 = x; @@ -307,19 +349,33 @@ SCM call (SCM fn, SCM x) { puts ("call\n"); - if ((FUNCTION (fn).arity > 0 || FUNCTION (fn).arity == -1) - && x != cell_nil && TYPE (CAR (x)) == TVALUES) + if ((FUNCTION (fn).arity > 0 || FUNCTION (fn).arity == -1) && x != cell_nil && TYPE (CAR (x)) == TVALUES) x = cons (CADAR (x), CDR (x)); if ((FUNCTION (fn).arity > 1 || FUNCTION (fn).arity == -1) && x != cell_nil && TYPE (CDR (x)) == TPAIR && TYPE (CADR (x)) == TVALUES) x = cons (CAR (x), cons (CDADAR (x), CDR (x))); switch (FUNCTION (fn).arity) { - case 0: {return (FUNCTION (fn).function) ();} - case 1: {return ((SCM(*)(SCM))(FUNCTION (fn).function)) (car (x));} - case 2: {return ((SCM(*)(SCM,SCM))(FUNCTION (fn).function)) (car (x), cadr (x));} - case 3: {return ((SCM(*)(SCM,SCM,SCM))(FUNCTION (fn).function)) (car (x), cadr (x), car (cddr (x)));} - case -1: {return ((SCM(*)(SCM))(FUNCTION (fn).function)) (x);} + case 0: + { + return (FUNCTION (fn).function) (); + } + case 1: + { + return ((SCM (*)(SCM)) (FUNCTION (fn).function)) (car (x)); + } + case 2: + { + return ((SCM (*)(SCM, SCM)) (FUNCTION (fn).function)) (car (x), cadr (x)); + } + case 3: + { + return ((SCM (*)(SCM, SCM, SCM)) (FUNCTION (fn).function)) (car (x), cadr (x), car (cddr (x))); + } + case -1: + { + return ((SCM (*)(SCM)) (FUNCTION (fn).function)) (x); + } } return cell_unspecified; } @@ -344,7 +400,7 @@ gc_pop_frame () } SCM -mes_g_stack (SCM a) ///((internal)) +mes_g_stack (SCM a) ///((internal)) { r0 = a; r1 = MAKE_CHAR (0); @@ -356,7 +412,7 @@ mes_g_stack (SCM a) ///((internal)) // Environment setup SCM -make_tmps (struct scm* cells) +make_tmps (struct scm * cells) { tmp = g_free++; cells[tmp].type = TCHAR; @@ -401,7 +457,7 @@ gc_init_cells () // INIT NEWS SCM -mes_symbols () ///((internal)) +mes_symbols () ///((internal)) { gc_init_cells (); // gc_init_news (); @@ -409,61 +465,61 @@ mes_symbols () ///((internal)) #if __GNUC__ && 0 //#include "mes.symbols.i" #else -g_free++; + g_free++; // g_cells[cell_nil] = scm_nil; -g_free++; + g_free++; // g_cells[cell_f] = scm_f; -g_free++; + g_free++; // g_cells[cell_t] = scm_t; -g_free++; + g_free++; // g_cells[cell_dot] = scm_dot; -g_free++; + g_free++; // g_cells[cell_arrow] = scm_arrow; -g_free++; + g_free++; // g_cells[cell_undefined] = scm_undefined; -g_free++; + g_free++; // g_cells[cell_unspecified] = scm_unspecified; -g_free++; + g_free++; // g_cells[cell_closure] = scm_closure; -g_free++; + g_free++; // g_cells[cell_circular] = scm_circular; -g_free++; + g_free++; // g_cells[cell_begin] = scm_begin; /// -g_free = 44; -g_free++; + g_free = 44; + g_free++; // g_cells[cell_vm_apply] = scm_vm_apply; -g_free++; + g_free++; // g_cells[cell_vm_apply2] = scm_vm_apply2; -g_free++; + g_free++; // g_cells[cell_vm_eval] = scm_vm_eval; /// -g_free = 55; -g_free++; + g_free = 55; + g_free++; // g_cells[cell_vm_begin] = scm_vm_begin; -g_free++; + g_free++; // g_cells[cell_vm_begin_read_input_file] = scm_vm_begin_read_input_file; -g_free++; + g_free++; // g_cells[cell_vm_begin2] = scm_vm_begin2; /// -g_free = 62; -g_free++; + g_free = 62; + g_free++; // g_cells[cell_vm_return] = scm_vm_return; #endif @@ -472,7 +528,7 @@ g_free++; make_tmps (g_cells); g_symbols = 0; - for (int i=1; i\n"); //if (cont != cell_f) puts "("); puts ("("); - if (x && x != cell_nil) display_ (CAR (x)); + if (x && x != cell_nil) + display_ (CAR (x)); if (CDR (x) && CDR (x) != cell_nil) { #if __GNUC__ @@ -678,17 +735,29 @@ display_ (SCM x) { switch (x) { - case 1: {puts ("()"); break;} - case 2: {puts ("#f"); break;} - case 3: {puts ("#t"); break;} + case 1: + { + puts ("()"); + break; + } + case 2: + { + puts ("#f"); + break; + } + case 3: + { + puts ("#t"); + break; + } default: { #if __GNUC__ - puts (""); + puts (""); #else - puts (""); + puts (""); #endif } } @@ -698,24 +767,64 @@ display_ (SCM x) { switch (x) { - case 11: {puts (" . "); break;} - case 12: {puts ("lambda"); break;} - case 13: {puts ("begin"); break;} - case 14: {puts ("if"); break;} - case 15: {puts ("quote"); break;} - case 37: {puts ("car"); break;} - case 38: {puts ("cdr"); break;} - case 39: {puts ("null?"); break;} - case 40: {puts ("eq?"); break;} - case 41: {puts ("cons"); break;} + case 11: + { + puts (" . "); + break; + } + case 12: + { + puts ("lambda"); + break; + } + case 13: + { + puts ("begin"); + break; + } + case 14: + { + puts ("if"); + break; + } + case 15: + { + puts ("quote"); + break; + } + case 37: + { + puts ("car"); + break; + } + case 38: + { + puts ("cdr"); + break; + } + case 39: + { + puts ("null?"); + break; + } + case 40: + { + puts ("eq?"); + break; + } + case 41: + { + puts ("cons"); + break; + } default: { #if __GNUC__ - puts (""); + puts (""); #else - puts (""); + puts (""); #endif } } @@ -740,16 +849,20 @@ display_ (SCM x) } SCM -simple_bload_env (SCM a) ///((internal)) +simple_bload_env (SCM a) ///((internal)) { puts ("reading: "); char *mo = "module/mes/tiny-0-32.mo"; puts (mo); puts ("\n"); __stdin = open (mo, 0); - if (__stdin < 0) {eputs ("no such file: module/mes/tiny-0-32.mo\n");return 1;} + if (__stdin < 0) + { + eputs ("no such file: module/mes/tiny-0-32.mo\n"); + return 1; + } - char *p = (char*)g_cells; + char *p = (char *) g_cells; int c; assert (getchar () == 'M'); @@ -773,17 +886,19 @@ simple_bload_env (SCM a) ///((internal)) puts ("read done\n"); - g_free = (p-(char*)g_cells) / sizeof (struct scm); - - if (g_free != 15) exit (33); - + g_free = (p - (char *) g_cells) / sizeof (struct scm); + + if (g_free != 15) + exit (33); + g_symbols = 1; __stdin = STDIN; r0 = mes_builtins (r0); - - if (g_free != 19) exit (34); - + + if (g_free != 19) + exit (34); + puts ("cells read: "); puts (itoa (g_free)); puts ("\n"); @@ -820,46 +935,55 @@ int main (int argc, char *argv[]) { puts ("Hello cons-mes!\n"); - if (argc > 1 && !strcmp (argv[1], "--help")) return eputs ("Usage: mes [--dump|--load] < FILE"); + if (argc > 1 && !strcmp (argv[1], "--help")) + return eputs ("Usage: mes [--dump|--load] < FILE"); #if __GNUC__ - if (argc > 1 && !strcmp (argv[1], "--version")) {eputs ("Mes ");return eputs (VERSION);}; + if (argc > 1 && !strcmp (argv[1], "--version")) + { + eputs ("Mes "); + return eputs (VERSION); + }; #else - if (argc > 1 && !strcmp (argv[1], "--version")) {eputs ("Mes ");return eputs ("0.4");}; + if (argc > 1 && !strcmp (argv[1], "--version")) + { + eputs ("Mes "); + return eputs ("0.4"); + }; #endif __stdin = STDIN; r0 = mes_environment (); - + SCM program = simple_bload_env (r0); puts ("g_free="); - puts (itoa(g_free)); + puts (itoa (g_free)); puts ("\n"); push_cc (r2, cell_unspecified, r0, cell_unspecified); puts ("g_free="); - puts (itoa(g_free)); + puts (itoa (g_free)); puts ("\n"); puts ("g_stack="); - puts (itoa(g_stack)); + puts (itoa (g_stack)); puts ("\n"); puts ("r0="); - puts (itoa(r0)); + puts (itoa (r0)); puts ("\n"); puts ("r1="); - puts (itoa(r1)); + puts (itoa (r1)); puts ("\n"); puts ("r2="); - puts (itoa(r2)); + puts (itoa (r2)); puts ("\n"); puts ("r3="); - puts (itoa(r3)); + puts (itoa (r3)); puts ("\n"); r3 = cell_vm_apply; @@ -869,4 +993,3 @@ main (int argc, char *argv[]) eputs ("\n"); return 0; } - diff --git a/scaffold/micro-mes.c b/scaffold/micro-mes.c index 4dda7a7c..f161eb36 100644 --- a/scaffold/micro-mes.c +++ b/scaffold/micro-mes.c @@ -35,10 +35,10 @@ int g_free = 0; SCM g_symbols = 0; SCM g_stack = 0; -SCM r0 = 0; // a/env -SCM r1 = 0; // param 1 -SCM r2 = 0; // save 2+load/dump -SCM r3 = 0; // continuation +SCM r0 = 0; // a/env +SCM r1 = 0; // param 1 +SCM r2 = 0; // save 2+load/dump +SCM r3 = 0; // continuation SCM mes_environment () @@ -47,7 +47,7 @@ mes_environment () } SCM -bload_env (SCM a) ///((internal)) +bload_env (SCM a) ///((internal)) { eputs ("bload_env\n"); return 0; @@ -57,7 +57,7 @@ int main (int argc, char *argv[]) { #if __GNUC__ - g_debug = (int)getenv ("MES_DEBUG"); + g_debug = (int) getenv ("MES_DEBUG"); #endif //if (getenv ("MES_ARENA")) ARENA_SIZE = atoi (getenv ("MES_ARENA")); diff --git a/scaffold/read.c b/scaffold/read.c index 0111a223..58b28ef9 100644 --- a/scaffold/read.c +++ b/scaffold/read.c @@ -29,8 +29,9 @@ main (int argc, char *argv[]) int c = getchar (); if (c != 'm') return 1; - while (c != EOF) { - putchar (c); - c = getchar (); - } + while (c != EOF) + { + putchar (c); + c = getchar (); + } } diff --git a/scaffold/tests/14-if-goto.c b/scaffold/tests/14-if-goto.c index 69810726..36c435e8 100644 --- a/scaffold/tests/14-if-goto.c +++ b/scaffold/tests/14-if-goto.c @@ -24,10 +24,10 @@ main () if (0 == 0) goto ok; return 1; - ok: +ok: if (0 != 1) goto ok1; return 1; - ok1: +ok1: return 0; } diff --git a/scaffold/tests/17-compare-unsigned-char-le.c b/scaffold/tests/17-compare-unsigned-char-le.c index 24a4e6ff..70977903 100644 --- a/scaffold/tests/17-compare-unsigned-char-le.c +++ b/scaffold/tests/17-compare-unsigned-char-le.c @@ -24,7 +24,7 @@ main () unsigned char r = -2; if (r <= -3) return 1; - if (r <= (unsigned char)-1) + if (r <= (unsigned char) -1) return 0; return 2; } diff --git a/scaffold/tests/17-compare-unsigned-short-le.c b/scaffold/tests/17-compare-unsigned-short-le.c index dead66e3..20b77ebc 100644 --- a/scaffold/tests/17-compare-unsigned-short-le.c +++ b/scaffold/tests/17-compare-unsigned-short-le.c @@ -24,7 +24,7 @@ main () unsigned short r = -2; if (r <= -3) return 1; - if (r <= (unsigned short)-1) + if (r <= (unsigned short) -1) return 0; return 2; } diff --git a/scaffold/tests/18-assign-shadow.c b/scaffold/tests/18-assign-shadow.c index c778ca0a..35317af6 100644 --- a/scaffold/tests/18-assign-shadow.c +++ b/scaffold/tests/18-assign-shadow.c @@ -24,7 +24,9 @@ int main () { int c = 0; - {int c = 3;} + { + int c = 3; + } if (c) return 1; diff --git a/scaffold/tests/32-call-wrap.c b/scaffold/tests/32-call-wrap.c index 0aa4603c..d8451d18 100644 --- a/scaffold/tests/32-call-wrap.c +++ b/scaffold/tests/32-call-wrap.c @@ -37,7 +37,7 @@ print (int a) int main () { - int a[2] = {101, -1}; + int a[2] = { 101, -1 }; //eputs ("b:"); eputs (itoa (a[0])); eputs ("\n"); int r = wrap (print (a[0])); if (r != 101) diff --git a/scaffold/tests/32-compare.c b/scaffold/tests/32-compare.c index 9644cdf6..69d53d38 100644 --- a/scaffold/tests/32-compare.c +++ b/scaffold/tests/32-compare.c @@ -79,83 +79,84 @@ main (int c) goto ok0; return 111; - ok0: +ok0: oputs ("t: if (0); return 1; else;\n"); if (0) - return 12; else + return 12; + else goto ok1; - ok1: +ok1: oputs ("t: if (t)\n"); if (t) goto ok2; return 13; - ok2: +ok2: oputs ("t: if (one > 0)\n"); if (one > 0) goto ok3; return 14; - ok3: +ok3: oputs ("t: if (one < 2)\n"); if (one < 2) goto ok4; return 15; - ok4: +ok4: oputs ("t: if (one >= 0)\n"); if (one >= 0) goto ok5; return 16; - ok5: +ok5: oputs ("t: if (one >= 1)\n"); if (one >= 0) goto ok6; return 17; - ok6: +ok6: oputs ("t: if (one <= 2)\n"); if (one <= 2) goto ok7; return 18; - ok7: +ok7: oputs ("t: if (one <= 1)\n"); if (one <= 1) goto ok8; return 19; - ok8: +ok8: oputs ("t: if (!0)\n"); if (!0) goto ok9; return 20; - ok9: +ok9: oputs ("t: if (one == 1)\n"); if (one == 1) goto ok10; return 21; - ok10: +ok10: oputs ("t: if (one != 0)\n"); if (one != 0) goto ok11; return 22; - ok11: +ok11: ; int m1 = -1; diff --git a/scaffold/tests/33-and-or.c b/scaffold/tests/33-and-or.c index 8f90f05b..39df31f2 100644 --- a/scaffold/tests/33-and-or.c +++ b/scaffold/tests/33-and-or.c @@ -47,14 +47,14 @@ main () oputs ("t: if (1 && !0)\n"); if (1 && !0) goto ok0; - return 1; - ok0: + return 1; +ok0: oputs ("t: if (f || t)\n"); if (f || t) goto ok1; return 1; - ok1: +ok1: return 0; } diff --git a/scaffold/tests/34-pre-post.c b/scaffold/tests/34-pre-post.c index 6e17654b..cbe5512f 100644 --- a/scaffold/tests/34-pre-post.c +++ b/scaffold/tests/34-pre-post.c @@ -51,13 +51,13 @@ main () if (++i) goto ok0; return 1; - ok0: +ok0: oputs ("t: if (i--)\n"); if (i--) goto ok1; return 1; - ok1: +ok1: return 0; } diff --git a/scaffold/tests/35-compare-char.c b/scaffold/tests/35-compare-char.c index 04f24e7e..7a2fb4aa 100644 --- a/scaffold/tests/35-compare-char.c +++ b/scaffold/tests/35-compare-char.c @@ -69,35 +69,35 @@ main () if (*g_chars == 'B') goto ok1; return 1; - ok1: +ok1: oputs ("t: *x == 'B'\n"); x = g_arena; if (*x == 'B') goto ok2; return 1; - ok2: +ok2: oputs ("t: *y == 'B'\n"); y = g_chars; if (*y == 'B') goto ok3; return 1; - ok3: +ok3: oputs ("t: *x == 'R'\n"); g_chars[0] = 'R'; if (*x == 'R') goto ok4; return 1; - ok4: +ok4: oputs ("t: *x++ == 'C'\n"); *x++ = c; if (*g_chars == 'C') goto ok5; return 1; - ok5: +ok5: return 0; } diff --git a/scaffold/tests/38-compare-call.c b/scaffold/tests/38-compare-call.c index 174b876a..29df580e 100644 --- a/scaffold/tests/38-compare-call.c +++ b/scaffold/tests/38-compare-call.c @@ -20,7 +20,9 @@ #include -enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART}; +enum type_t +{ TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, + TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART }; int add (int a, int b) @@ -102,13 +104,13 @@ main () if (strlen (".")) goto ok1; return 11; - ok1: +ok1: oputs ("t: if (strlen (p) == 3)\n"); if (strlen (p) == 3) goto ok2; return 12; - ok2: +ok2: return 0; } diff --git a/scaffold/tests/42-goto-label.c b/scaffold/tests/42-goto-label.c index 75c3297f..322d56b4 100644 --- a/scaffold/tests/42-goto-label.c +++ b/scaffold/tests/42-goto-label.c @@ -23,7 +23,7 @@ int label (int c) { - label: +label: if (c == 0) return c; c--; diff --git a/scaffold/tests/43-for-do-while.c b/scaffold/tests/43-for-do-while.c index 81a62661..acc686a5 100644 --- a/scaffold/tests/43-for-do-while.c +++ b/scaffold/tests/43-for-do-while.c @@ -32,14 +32,14 @@ main () oputs ("\n"); oputs ("t: for (i=1; i<5; ++i)\n"); - for (i=1; i<5; ++i) + for (i = 1; i < 5; ++i) ; if (i != 5) return i; oputs ("t: while (i<3) i++\n"); i = 1; - while (i<3) + while (i < 3) i++; if (i != 3) return i; @@ -47,8 +47,8 @@ main () oputs ("t: do i-- while (i>0)\n"); do i--; - while (i>0) - ; + while (i > 0) + ; if (i != 0) return 1; @@ -59,7 +59,7 @@ main () oputs ("t: while (1) ... break;\n"); while (1) { - f=0; + f = 0; break; } @@ -75,7 +75,7 @@ main () while (one--) { continue; - one=1; + one = 1; } one += 2; @@ -84,7 +84,7 @@ main () { goto ok1; } - ok1: +ok1: return 0; } diff --git a/scaffold/tests/44-switch-body-fallthrough.c b/scaffold/tests/44-switch-body-fallthrough.c index affa844b..1085081c 100644 --- a/scaffold/tests/44-switch-body-fallthrough.c +++ b/scaffold/tests/44-switch-body-fallthrough.c @@ -25,19 +25,20 @@ main () { int r; int i = 2; - switch (i) { - // case 0: - // r = 0; - // break; - // case 1: - // r = 1; - // break; + switch (i) + { + // case 0: + // r = 0; + // break; + // case 1: + // r = 1; + // break; case 2: r = 2; default: r++; break; - } + } if (r != 3) return 1; diff --git a/scaffold/tests/44-switch-fallthrough.c b/scaffold/tests/44-switch-fallthrough.c index 5ac83ff7..eadd73da 100644 --- a/scaffold/tests/44-switch-fallthrough.c +++ b/scaffold/tests/44-switch-fallthrough.c @@ -25,18 +25,19 @@ main () { int r; int i = 2; - switch (i) { - // case 0: - // r = 0; - // break; - // case 1: - // r = 1; - // break; + switch (i) + { + // case 0: + // r = 0; + // break; + // case 1: + // r = 1; + // break; case 2: default: r = 2; break; - } + } if (r != 2) return 1; diff --git a/scaffold/tests/44-switch.c b/scaffold/tests/44-switch.c index 6f238d8d..fa6a4716 100644 --- a/scaffold/tests/44-switch.c +++ b/scaffold/tests/44-switch.c @@ -20,7 +20,9 @@ #include -enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART}; +enum type_t +{ TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, + TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART }; int swits (int c) @@ -52,7 +54,7 @@ swits (int c) } return 1; - next: +next: switch (c) { case 0: @@ -96,7 +98,8 @@ default_first (int c) there: case 0: ; - {} + { + } return 0; } return -1; @@ -153,7 +156,7 @@ main () break; } - if (i!= 0) + if (i != 0) return 16; i = 2; diff --git a/scaffold/tests/47-function-expression.c b/scaffold/tests/47-function-expression.c index f818322b..ee1beeb8 100644 --- a/scaffold/tests/47-function-expression.c +++ b/scaffold/tests/47-function-expression.c @@ -24,7 +24,7 @@ int g_time = 1; #define time time_ #endif -int* +int * time () { return &g_time; diff --git a/scaffold/tests/48-global-static.c b/scaffold/tests/48-global-static.c index e5986d55..cb82197a 100644 --- a/scaffold/tests/48-global-static.c +++ b/scaffold/tests/48-global-static.c @@ -25,7 +25,7 @@ static int sint; static int sint2, sint3; typedef unsigned int size; -static void* +static void * test (size u) { void *r; @@ -37,7 +37,7 @@ static int i = 2; int main () { - void (*foo)() = &test; + void (*foo) () = &test; test (0); return 0; } diff --git a/scaffold/tests/51-pointer-sub.c b/scaffold/tests/51-pointer-sub.c index c289d239..76f671ca 100644 --- a/scaffold/tests/51-pointer-sub.c +++ b/scaffold/tests/51-pointer-sub.c @@ -25,7 +25,9 @@ main () { int **p = 1; int **q = -1; - oputs ("p - q"); oputs (itoa (p - q)); oputs ("\n"); + oputs ("p - q"); + oputs (itoa (p - q)); + oputs ("\n"); return 0; } diff --git a/scaffold/tests/54-argc.c b/scaffold/tests/54-argc.c index 3388a02e..baba655c 100644 --- a/scaffold/tests/54-argc.c +++ b/scaffold/tests/54-argc.c @@ -26,7 +26,9 @@ int main (int argc, char *argv[]) { - oputs ("argc="); oputs (itoa (argc)); oputs ("\n"); + oputs ("argc="); + oputs (itoa (argc)); + oputs ("\n"); if (argc != 1) return 1; diff --git a/scaffold/tests/54-argv.c b/scaffold/tests/54-argv.c index cdabdc39..7b9965e4 100644 --- a/scaffold/tests/54-argv.c +++ b/scaffold/tests/54-argv.c @@ -28,7 +28,9 @@ main (int argc, char *argv[]) { oputs ("\n"); oputs ("t: argv[0] == \"scaffold/test....\"\n"); - oputs ("argv0="); oputs (argv[0]); oputs ("\n"); + oputs ("argv0="); + oputs (argv[0]); + oputs ("\n"); if (strncmp (argv[0], "scaffold/test", 5)) return 1; diff --git a/scaffold/tests/55-char-array.c b/scaffold/tests/55-char-array.c index 34d2485b..41b327e5 100644 --- a/scaffold/tests/55-char-array.c +++ b/scaffold/tests/55-char-array.c @@ -18,25 +18,19 @@ * along with GNU Mes. If not, see . */ -char g_hello[] = - "hello\n" - "world\n" - ; +char g_hello[] = "hello\n" "world\n"; -char *g_hello2 = - "hello\n" - "world\n" - ; +char *g_hello2 = "hello\n" "world\n"; -char g_hello3[] = - { - 'h', 'e', 'l', 'l', 'o', '\n', - 'w', 'o', 'r', 'l', 'd', '\n', - '\0', - } - ; +char g_hello3[] = { + 'h', 'e', 'l', 'l', 'o', '\n', + 'w', 'o', 'r', 'l', 'd', '\n', + '\0', +} -int g_hello_int[] = {0, 1, 2, 3, 4, 5}; +; + +int g_hello_int[] = { 0, 1, 2, 3, 4, 5 }; int main (int argc) diff --git a/scaffold/tests/60-math.c b/scaffold/tests/60-math.c index dd06370c..19d7edd2 100644 --- a/scaffold/tests/60-math.c +++ b/scaffold/tests/60-math.c @@ -78,13 +78,13 @@ main () if (1 == inc (0)) goto ok0; return 10; - ok0: +ok0: oputs ("t: 0 < inc (0)\n"); if (0 < inc (0)) goto ok1; return 11; - ok1: +ok1: oputs ("t: inc (0) + 2 != 3\n"); if (inc (0) + inc (1) != 3) @@ -92,7 +92,7 @@ main () oputs ("t: 4/2="); i = 4 / 2; - if (i!=2) + if (i != 2) return 13; i += 48; putchar (i); @@ -100,17 +100,17 @@ main () oputs ("t: 3*4=\n"); i = 3 * 4; - if (i!=12) + if (i != 12) return 14; oputs ("t: i /= 4\n"); i /= 4; - if (i!=3) + if (i != 3) return 15; oputs ("t: i *= 4\n"); i *= 4; - if (i!=12) + if (i != 12) return 16; oputs ("t: 1 << 3\n"); @@ -159,11 +159,11 @@ main () return 27; oputs ("t: 3 == 3\n"); - if ((3 == 3) != 1) + if ((3 == 3) != 1) return 28; oputs ("t: 3 != 3\n"); - if ((3 != 3) != 0) + if ((3 != 3) != 0) return 29; oputs ("t: 011 == 15\n"); @@ -171,7 +171,7 @@ main () return 30; oputs ("t: 0b11 == 3\n"); - if (0b11 != 3) + if (0 b11 != 3) return 31; oputs ("t: 0x11 == 3\n"); diff --git a/scaffold/tests/61-array.c b/scaffold/tests/61-array.c index 754393f9..a3056101 100644 --- a/scaffold/tests/61-array.c +++ b/scaffold/tests/61-array.c @@ -24,22 +24,28 @@ #include #include -char *env[] = {"foo", "bar", "baz", 0}; +char *env[] = { "foo", "bar", "baz", 0 }; -#if 0//!WITH_GLIBC +#if 0 //!WITH_GLIBC #define getenv xgetenv char * -getenv (char const* s) +getenv (char const *s) { eputs ("getenv\n"); char **p = environ; int length = strlen (s); - eputs ("getenv length="); eputs (itoa (length)); eputs ("\n"); + eputs ("getenv length="); + eputs (itoa (length)); + eputs ("\n"); while (*p) { - eputs ("*p="); eputs (*p); eputs ("\n");; - eputs (" p="); eputs (itoa ((long)p)); eputs ("\n"); + eputs ("*p="); + eputs (*p); + eputs ("\n");; + eputs (" p="); + eputs (itoa ((long) p)); + eputs ("\n"); if (!strncmp (s, *p, length) && *(*p + length) == '=') return (*p + length + 1); p++; @@ -56,18 +62,18 @@ test (char **e) oputs ("\n"); oputs ("a[i] = i-1\n"); int a[3]; - for (int i=0; i < 3; i++) - a[i] = i-1; - for (int i=0; i < 3; i++) - if (a[i] != i-1) - return 1; + for (int i = 0; i < 3; i++) + a[i] = i - 1; + for (int i = 0; i < 3; i++) + if (a[i] != i - 1) + return 1; oputs ("env ["); - oputs (itoa ((long)env)); + oputs (itoa ((long) env)); oputs ("]\n"); oputs ("e ["); - oputs (itoa ((int)e)); + oputs (itoa ((int) e)); oputs ("]\n"); oputs ("env [0] == \"foo\"\n"); @@ -84,7 +90,7 @@ test (char **e) while (*pp) { oputs ("pp ["); - oputs (itoa ((int)pp)); + oputs (itoa ((int) pp)); oputs ("]: "); if (*pp) oputs (*pp); @@ -110,7 +116,7 @@ test (char **e) return 6; oputs ("t: buf + 1\n"); - if (*(buf+1) != 'e') + if (*(buf + 1) != 'e') return 7; char **p = &buf; diff --git a/scaffold/tests/62-array.c b/scaffold/tests/62-array.c index cfb20a87..7f2dcad8 100644 --- a/scaffold/tests/62-array.c +++ b/scaffold/tests/62-array.c @@ -19,18 +19,15 @@ */ #include -int one_two_three[3] = -{ +int one_two_three[3] = { 1, 2, 3 }; -char *foo_bar_baz[3] = -{ +char *foo_bar_baz[3] = { "foo", "bar", "baz" }; -char foo_bar_baz_haha[3][4] = -{ +char foo_bar_baz_haha[3][4] = { "foo", "bar", "baz" }; @@ -38,18 +35,25 @@ char *foo = "foo"; char *bar = "bar"; char *baz = "baz"; -char *foo_bar_baz_mwhuhahaha[3] = -{ +char *foo_bar_baz_mwhuhahaha[3] = { &foo, &bar, &baz }; int main () { - puts ("one:"); puts (itoa (one_two_three[0])); puts ("\n"); - puts ("foo:"); puts (foo_bar_baz[1]); puts ("\n"); - puts ("bar:"); puts (foo_bar_baz_haha[2]); puts ("\n"); + puts ("one:"); + puts (itoa (one_two_three[0])); + puts ("\n"); + puts ("foo:"); + puts (foo_bar_baz[1]); + puts ("\n"); + puts ("bar:"); + puts (foo_bar_baz_haha[2]); + puts ("\n"); char *p = foo_bar_baz_haha[2]; - puts ("baz:"); puts (p); puts ("\n"); + puts ("baz:"); + puts (p); + puts ("\n"); return strcmp (foo_bar_baz[2], "baz"); } diff --git a/scaffold/tests/63-struct-array-assign.c b/scaffold/tests/63-struct-array-assign.c index 093c2a67..7c755019 100644 --- a/scaffold/tests/63-struct-array-assign.c +++ b/scaffold/tests/63-struct-array-assign.c @@ -29,7 +29,7 @@ struct scm char g_arena[24]; -struct scm *g_cells = (struct scm*)g_arena; +struct scm *g_cells = (struct scm *) g_arena; int main () diff --git a/scaffold/tests/63-struct-array-compare.c b/scaffold/tests/63-struct-array-compare.c index d0db546c..e6d2a2df 100644 --- a/scaffold/tests/63-struct-array-compare.c +++ b/scaffold/tests/63-struct-array-compare.c @@ -29,7 +29,7 @@ struct scm char g_arena[24]; -struct scm *g_cells = (struct scm*)g_arena; +struct scm *g_cells = (struct scm *) g_arena; int main () @@ -45,7 +45,7 @@ main () if (g_cells[0].type == g_cells[1].type) goto ok; return 1; - ok: +ok: return 0; } diff --git a/scaffold/tests/63-struct-array.c b/scaffold/tests/63-struct-array.c index eb6aecd5..45c73db9 100644 --- a/scaffold/tests/63-struct-array.c +++ b/scaffold/tests/63-struct-array.c @@ -29,7 +29,7 @@ struct scm char g_arena[12]; -struct scm *g_cells = (struct scm*)g_arena; +struct scm *g_cells = (struct scm *) g_arena; int main () diff --git a/scaffold/tests/63-struct-assign.c b/scaffold/tests/63-struct-assign.c index 6c17d706..462a48cc 100644 --- a/scaffold/tests/63-struct-assign.c +++ b/scaffold/tests/63-struct-assign.c @@ -28,8 +28,8 @@ struct scm }; -struct scm a = {-1, 0,-1}; -struct scm b = { 0,-1, 0}; +struct scm a = { -1, 0, -1 }; +struct scm b = { 0, -1, 0 }; int main () diff --git a/scaffold/tests/63-struct-cell.c b/scaffold/tests/63-struct-cell.c index 2b5a3004..2af86e0c 100644 --- a/scaffold/tests/63-struct-cell.c +++ b/scaffold/tests/63-struct-cell.c @@ -36,7 +36,8 @@ inc (int i) return i + 1; } -struct scm { +struct scm +{ int type; int car; int cdr; @@ -47,12 +48,24 @@ char g_arena[84]; #if __MESC__ struct scm *g_cells = g_arena; #else -struct scm *g_cells = (struct scm*)g_arena; +struct scm *g_cells = (struct scm *) g_arena; #endif char *g_chars = g_arena; -int foo () {oputs ("t: foo\n"); return 0;}; -int bar (int i) {oputs ("t: bar\n"); return 0;}; +int +foo () +{ + oputs ("t: foo\n"); + return 0; +}; + +int +bar (int i) +{ + oputs ("t: bar\n"); + return 0; +}; + struct function { int (*function) (void); @@ -60,9 +73,9 @@ struct function //long arity; char *name; }; -struct function g_fun = {&exit,1,"fun"}; -struct function g_foo = {&foo,0,"foo"}; -struct function g_bar = {&bar,1,"bar"}; +struct function g_fun = { &exit, 1, "fun" }; +struct function g_foo = { &foo, 0, "foo" }; +struct function g_bar = { &bar, 1, "bar" }; void *functions[2]; //int functions[2]; @@ -70,7 +83,9 @@ void *functions[2]; struct function g_functions[2]; int g_function = 0; -enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART}; +enum type_t +{ TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, + TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART }; typedef int SCM; int g_free = 3; @@ -85,7 +100,8 @@ int ARENA_SIZE = 200; #define CAAR(x) CAR (CAR (x)) -struct scm scm_fun = {TFUNCTION,0,0}; +struct scm scm_fun = { TFUNCTION, 0, 0 }; + SCM cell_fun; @@ -123,7 +139,7 @@ main () TYPE (1) = 1; CAR (1) = 2; CDR (1) = 3; - g_cells[0+add(0, 0)] = g_cells[0+inc(0)]; + g_cells[0 + add (0, 0)] = g_cells[0 + inc (0)]; if (TYPE (0) != 1) return 7; if (CAR (0) != 2) @@ -142,7 +158,7 @@ main () if (TYPE (0) == TYPE (1)) goto ok; return 10; - ok: +ok: g_cells[0].car = 1; g_cells[1].car = 2; @@ -182,7 +198,7 @@ main () return 17; oputs ("t: struct fun = {&exit,1,\"exit\"};\n"); - struct function fun = {&exit,1,"exit"}; + struct function fun = { &exit, 1, "exit" }; oputs ("t: fun.arity != 1;\n"); if (fun.arity != 1) @@ -204,7 +220,7 @@ main () g_functions[g_function++] = g_foo; oputs ("t: pbar->arity == 1\n"); - struct function* barp = &g_bar; + struct function *barp = &g_bar; if (barp->arity != 1) return 22; diff --git a/scaffold/tests/63-struct-function.c b/scaffold/tests/63-struct-function.c index 1e0d6524..7bb73614 100644 --- a/scaffold/tests/63-struct-function.c +++ b/scaffold/tests/63-struct-function.c @@ -27,7 +27,8 @@ struct function int arity; char *name; }; -struct function g_fun = {&exit,1,"fun"}; +struct function g_fun = { &exit, 1, "fun" }; + int functions[2]; int g_function = 0; diff --git a/scaffold/tests/63-struct-local.c b/scaffold/tests/63-struct-local.c index 52c8a14c..7344bc8e 100644 --- a/scaffold/tests/63-struct-local.c +++ b/scaffold/tests/63-struct-local.c @@ -30,7 +30,7 @@ struct scm int main () { - struct scm a = {-1, 0,-1}; + struct scm a = { -1, 0, -1 }; if (a.type != -1) return 1; diff --git a/scaffold/tests/63-struct-pointer.c b/scaffold/tests/63-struct-pointer.c index 8e9115ec..4019eeef 100644 --- a/scaffold/tests/63-struct-pointer.c +++ b/scaffold/tests/63-struct-pointer.c @@ -27,7 +27,8 @@ struct scm int cdr; }; -struct scm a = {-1, 0,-1}; +struct scm a = { -1, 0, -1 }; + struct scm *p = &a; int diff --git a/scaffold/tests/63-struct.c b/scaffold/tests/63-struct.c index 2b339237..78212d9a 100644 --- a/scaffold/tests/63-struct.c +++ b/scaffold/tests/63-struct.c @@ -27,7 +27,7 @@ struct scm int cdr; }; -struct scm a = {-1, 0,-1}; +struct scm a = { -1, 0, -1 }; int main () diff --git a/scaffold/tests/64-make-cell.c b/scaffold/tests/64-make-cell.c index 5845c98d..33a3b1f8 100644 --- a/scaffold/tests/64-make-cell.c +++ b/scaffold/tests/64-make-cell.c @@ -24,7 +24,8 @@ #include #include -struct scm { +struct scm +{ int type; int car; int cdr; @@ -32,19 +33,32 @@ struct scm { int bla = 1234; char g_arena[84]; -struct scm *g_cells = (struct scm*)g_arena; +struct scm *g_cells = (struct scm *) g_arena; char *g_chars = g_arena; -int foo () {oputs ("t: foo\n"); return 0;}; -int bar (int i) {oputs ("t: bar\n"); return 0;}; -struct function { +int +foo () +{ + oputs ("t: foo\n"); + return 0; +}; + +int +bar (int i) +{ + oputs ("t: bar\n"); + return 0; +}; + +struct function +{ int (*function) (void); int arity; char *name; }; -struct function g_fun = {&exit,1,"fun"}; -struct function g_foo = {&foo,0,"foo"}; -struct function g_bar = {&bar,1,"bar"}; +struct function g_fun = { &exit, 1, "fun" }; +struct function g_foo = { &foo, 0, "foo" }; +struct function g_bar = { &bar, 1, "bar" }; //void *functions[2]; int functions[2]; @@ -52,7 +66,9 @@ int functions[2]; struct function g_functions[2]; int g_function = 0; -enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART}; +enum type_t +{ TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, + TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART }; typedef int SCM; int g_free = 3; @@ -67,7 +83,8 @@ int ARENA_SIZE = 200; #define CAAR(x) CAR (CAR (x)) -struct scm scm_fun = {TFUNCTION,0,0}; +struct scm scm_fun = { TFUNCTION, 0, 0 }; + SCM cell_fun; SCM @@ -85,18 +102,25 @@ make_cell (SCM type, SCM car, SCM cdr) oputs ("030\n"); SCM x = alloc (1); TYPE (x) = VALUE (type); - if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER) { - if (car) CAR (x) = CAR (car); - if (cdr) CDR(x) = CDR(cdr); - } - else if (VALUE (type) == TFUNCTION) { - if (car) CAR (x) = car; - if (cdr) CDR(x) = CDR(cdr); - } - else { - CAR (x) = car; - CDR(x) = cdr; - } + if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER) + { + if (car) + CAR (x) = CAR (car); + if (cdr) + CDR (x) = CDR (cdr); + } + else if (VALUE (type) == TFUNCTION) + { + if (car) + CAR (x) = car; + if (cdr) + CDR (x) = CDR (cdr); + } + else + { + CAR (x) = car; + CDR (x) = cdr; + } return x; } @@ -112,7 +136,7 @@ make_cell_test () } SCM -make_tmps_test (struct scm* cells) +make_tmps_test (struct scm * cells) { oputs ("t: tmp = g_free++\n"); tmp = g_free++; diff --git a/scaffold/tests/65-read.c b/scaffold/tests/65-read.c index a492fa1e..c96417d7 100644 --- a/scaffold/tests/65-read.c +++ b/scaffold/tests/65-read.c @@ -35,7 +35,7 @@ char g_arena[84]; #if __MESC__ struct scm *g_cells = g_arena; #else -struct scm *g_cells = (struct scm*)g_arena; +struct scm *g_cells = (struct scm *) g_arena; #endif char *g_chars = g_arena; @@ -51,7 +51,7 @@ get () int main () { - char *p = (char*)g_chars; + char *p = (char *) g_chars; int i = 0; oputs ("\n: "); diff --git a/scaffold/tests/66-local-char-array.c b/scaffold/tests/66-local-char-array.c index 71d26db2..37433f1f 100644 --- a/scaffold/tests/66-local-char-array.c +++ b/scaffold/tests/66-local-char-array.c @@ -46,33 +46,35 @@ calloc (size_t nmemb, size_t size) } /* {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'} */ -char little_endian_table[16] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46}; +char little_endian_table[16] = + { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 }; -char* -little_endian (unsigned value, char* c, int number_of_bytes) +char * +little_endian (unsigned value, char *c, int number_of_bytes) { - char table[16] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46}; + char table[16] = + { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 }; - switch(number_of_bytes) + switch (number_of_bytes) { case 4: { c[6] = table[value >> 28]; - c[7] = table[(value >> 24)% 16]; + c[7] = table[(value >> 24) % 16]; } case 3: { - c[4] = table[(value >> 20)% 16]; - c[5] = table[(value >> 16)% 16]; + c[4] = table[(value >> 20) % 16]; + c[5] = table[(value >> 16) % 16]; } case 2: { - c[2] = table[(value >> 12)% 16]; - c[3] = table[(value >> 8)% 16]; + c[2] = table[(value >> 12) % 16]; + c[3] = table[(value >> 8) % 16]; } case 1: { - c[0] = table[(value >> 4)% 16]; + c[0] = table[(value >> 4) % 16]; c[1] = table[value % 16]; break; } @@ -85,19 +87,25 @@ little_endian (unsigned value, char* c, int number_of_bytes) int main () { - char table[3] = {'0', '1', '2'}; + char table[3] = { '0', '1', '2' }; char *s; s = calloc (10, sizeof (char)); - eputs ("2="); eputs (little_endian (2, s, 1)); eputs ("\n"); + eputs ("2="); + eputs (little_endian (2, s, 1)); + eputs ("\n"); if (strcmp (s, "02")) return 1; - eputs ("8="); eputs (little_endian (8, s, 2)); eputs ("\n"); + eputs ("8="); + eputs (little_endian (8, s, 2)); + eputs ("\n"); if (strcmp (s, "0800")) return 2; - eputs ("16="); eputs (little_endian (16, s, 4)); eputs ("\n"); + eputs ("16="); + eputs (little_endian (16, s, 4)); + eputs ("\n"); if (strcmp (s, "10000000")) return 3; diff --git a/scaffold/tests/70-stdarg.c b/scaffold/tests/70-stdarg.c index 3c2c9ff0..28182f11 100644 --- a/scaffold/tests/70-stdarg.c +++ b/scaffold/tests/70-stdarg.c @@ -23,7 +23,7 @@ int //stdarg1 (long one, ...) -stdarg1 (long* one, ...) +stdarg1 (long *one, ...) { va_list ap; char c; @@ -37,7 +37,9 @@ stdarg1 (long* one, ...) #endif c = va_arg (ap, char); r = c; - eputs ("c:"); eputs (itoa (c)); eputs ("\n"); + eputs ("c:"); + eputs (itoa (c)); + eputs ("\n"); va_end (ap); return r; @@ -45,7 +47,7 @@ stdarg1 (long* one, ...) int ///stdarg2 (long one, long two, ...) -stdarg2 (long* one, long* two, ...) +stdarg2 (long *one, long *two, ...) { va_list ap; char c; @@ -59,7 +61,9 @@ stdarg2 (long* one, long* two, ...) #endif c = va_arg (ap, char); r = c; - eputs ("c:"); eputs (itoa (c)); eputs ("\n"); + eputs ("c:"); + eputs (itoa (c)); + eputs ("\n"); va_end (ap); return r; @@ -67,7 +71,7 @@ stdarg2 (long* one, long* two, ...) int //stdarg3 (long one, long two, long three, ...) -stdarg3 (long *one, long* two, long* three, ...) +stdarg3 (long *one, long *two, long *three, ...) { va_list ap; char c; @@ -81,7 +85,9 @@ stdarg3 (long *one, long* two, long* three, ...) #endif c = va_arg (ap, char); r = c; - eputs ("c:"); eputs (itoa (c)); eputs ("\n"); + eputs ("c:"); + eputs (itoa (c)); + eputs ("\n"); va_end (ap); return r; diff --git a/scaffold/tests/71-struct-array.c b/scaffold/tests/71-struct-array.c index cedabb34..8ef70e93 100644 --- a/scaffold/tests/71-struct-array.c +++ b/scaffold/tests/71-struct-array.c @@ -24,7 +24,7 @@ struct foo; -struct foo* krak; +struct foo *krak; typedef struct foo foo_struct; @@ -59,8 +59,10 @@ main () printf ("tweetje: %d\n", f.bar[1]); int *pf = &f; - if (*pf != 0x22) return 1; - if (*(pf + 1) != 0x34) return 2; + if (*pf != 0x22) + return 1; + if (*(pf + 1) != 0x34) + return 2; struct foo *g = &f; printf ("punter eentje: %d\n", g->bar[0]); @@ -84,7 +86,7 @@ main () oputs (g_foo.name); char buf[10]; - struct foo* s = &buf; + struct foo *s = &buf; strcpy (s->name, "hi\n"); oputs (s->name); diff --git a/scaffold/tests/72-typedef-struct-def.c b/scaffold/tests/72-typedef-struct-def.c index dd46f0a0..1ef83c0a 100644 --- a/scaffold/tests/72-typedef-struct-def.c +++ b/scaffold/tests/72-typedef-struct-def.c @@ -34,7 +34,7 @@ typedef struct } bar; -bar baz[2] = {1, 2, 3, 4, 5, 6}; +bar baz[2] = { 1, 2, 3, 4, 5, 6 }; bar *list[2]; @@ -49,19 +49,21 @@ bar *list[2]; int main () { - foo f = {1}; + foo f = { 1 }; printf ("f.i=%d\n", f.i); - bar b = {1, 2, &f}; + bar b = { 1, 2, &f }; printf ("b.i=%d\n", b.i); printf ("b.f.i=%d\n", b.f.i); - if (b.f.i != 2) return 1; + if (b.f.i != 2) + return 1; printf ("b.p->i=%d\n", b.p->i); - if (b.p->i != 1) return 2; + if (b.p->i != 1) + return 2; - bar* p = &b; + bar *p = &b; p->i = 2; printf ("p->i=%d\n", b.i); @@ -72,26 +74,31 @@ main () printf ("p->i=%d\n", b.i); printf ("p->f.i=%d\n", p->f.i); - if (p->f.i != 2) return 3; + if (p->f.i != 2) + return 3; printf ("p->p->i=%d\n", p->p->i); - if (p->p->i != 1) return 4; + if (p->p->i != 1) + return 4; - bar** pp = &p; + bar **pp = &p; (*pp)->i = 3; printf ("(*pp)->i=%d\n", b.i); printf ("sizeof i:%d\n", sizeof (p->i)); - if ((sizeof p->i) != 4) return 5; + if ((sizeof p->i) != 4) + return 5; - printf ("offsetof g=%d\n", (offsetof (bar ,f))); + printf ("offsetof g=%d\n", (offsetof (bar, f))); #if __MESC__ //if ((offsetof (bar ,f)) != 4) return 6; //#define offsetof(type, field) (&((type *)0)->field) - if ((&((bar *)0)->f) != 4) return 6; + if ((&((bar *) 0)->f) != 4) + return 6; #else - if ((offsetof (bar ,f)) != 4) return 6; + if ((offsetof (bar, f)) != 4) + return 6; #endif diff --git a/scaffold/tests/73-union-hello.c b/scaffold/tests/73-union-hello.c index 19205f0c..5004cc9f 100644 --- a/scaffold/tests/73-union-hello.c +++ b/scaffold/tests/73-union-hello.c @@ -30,7 +30,7 @@ typedef union foo int main () { - union foo f = {48}; + union foo f = { 48 }; if (f.i != 48) return 1; diff --git a/scaffold/tests/73-union.c b/scaffold/tests/73-union.c index 3c446488..ac78a187 100644 --- a/scaffold/tests/73-union.c +++ b/scaffold/tests/73-union.c @@ -39,12 +39,14 @@ typedef union int main () { - union foo f = {48}; + union foo f = { 48 }; printf ("f.i=%d\n", f.i); printf ("f.c=%c\n", f.c); - if (f.i != 48) return 1; - if (f.c != '0') return 1; + if (f.i != 48) + return 1; + if (f.c != '0') + return 1; return 0; } diff --git a/scaffold/tests/74-multi-line-string.c b/scaffold/tests/74-multi-line-string.c index ba2bfa82..8263b6da 100644 --- a/scaffold/tests/74-multi-line-string.c +++ b/scaffold/tests/74-multi-line-string.c @@ -22,11 +22,7 @@ #include #include -char const* help = - "All" - " your" - " base" - " are"; +char const *help = "All" " your" " base" " are"; int global_i = 1; int *global_p = &global_i; @@ -47,5 +43,5 @@ main () if (global_i != 2) return global_i; - return 2,1,0; + return 2, 1, 0; } diff --git a/scaffold/tests/75-struct-union.c b/scaffold/tests/75-struct-union.c index 08f89399..bc7b51f5 100644 --- a/scaffold/tests/75-struct-union.c +++ b/scaffold/tests/75-struct-union.c @@ -21,7 +21,8 @@ #include #include -union u { +union u +{ int bar; int baz; }; @@ -33,7 +34,8 @@ struct foo struct anon { - union { + union + { int bar; int baz; }; @@ -43,17 +45,21 @@ struct anon int main () { - struct foo f = {2}; + struct foo f = { 2 }; printf ("f.u.bar=%d\n", f.u.bar); - if (f.u.bar != 2) return 1; + if (f.u.bar != 2) + return 1; printf ("f.u.baz=%d\n", f.u.baz); - if (f.u.baz != 2) return 1; + if (f.u.baz != 2) + return 1; - struct anon a = {2}; + struct anon a = { 2 }; printf ("a.bar=%d\n", a.bar); - if (a.bar != 2) return 1; + if (a.bar != 2) + return 1; printf ("a.baz=%d\n", a.baz); - if (a.baz != 2) return 1; - + if (a.baz != 2) + return 1; + return 0; } diff --git a/scaffold/tests/76-pointer-arithmetic.c b/scaffold/tests/76-pointer-arithmetic.c index d76c494e..0ba46121 100644 --- a/scaffold/tests/76-pointer-arithmetic.c +++ b/scaffold/tests/76-pointer-arithmetic.c @@ -21,9 +21,10 @@ #include #include -char *list[2] = {"foo\n", "bar\n"}; +char *list[2] = { "foo\n", "bar\n" }; -struct foo { +struct foo +{ int a; int b; int c; @@ -43,11 +44,17 @@ main () void **ppv = 0; int **ppi = 0; int int_size = sizeof (int); - int ptr_size = sizeof (void*); + int ptr_size = sizeof (void *); int foo_size = sizeof (struct foo); - oputs ("int_size:"); oputs (itoa (int_size)); oputs ("\n"); - oputs ("ptr_size:"); oputs (itoa (ptr_size)); oputs ("\n"); - oputs ("foo_size:"); oputs (itoa (foo_size)); oputs ("\n"); + oputs ("int_size:"); + oputs (itoa (int_size)); + oputs ("\n"); + oputs ("ptr_size:"); + oputs (itoa (ptr_size)); + oputs ("\n"); + oputs ("foo_size:"); + oputs (itoa (foo_size)); + oputs ("\n"); // FIXME: add *14, *18 #if __i386__ int foo_size_14 = 224; @@ -92,81 +99,113 @@ main () if (strcmp (*p, "foo\n")) return 14; - struct foo* pfoo = 0; - eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); + struct foo *pfoo = 0; + eputs ("pfoo="); + eputs (itoa (pfoo)); + eputs ("\n"); pfoo++; - eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); + eputs ("pfoo="); + eputs (itoa (pfoo)); + eputs ("\n"); if (pfoo != foo_size) return 15; pfoo--; - eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); + eputs ("pfoo="); + eputs (itoa (pfoo)); + eputs ("\n"); if (pfoo) return 16; pfoo++; - eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); + eputs ("pfoo="); + eputs (itoa (pfoo)); + eputs ("\n"); if (pfoo != foo_size) return 17; long one = 1; long two = 2; pfoo = pfoo - one; - eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); + eputs ("pfoo="); + eputs (itoa (pfoo)); + eputs ("\n"); if (pfoo) return 18; pfoo = pfoo + one; - eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); + eputs ("pfoo="); + eputs (itoa (pfoo)); + eputs ("\n"); if (pfoo != foo_size) return 19; pfoo -= one; - eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); + eputs ("pfoo="); + eputs (itoa (pfoo)); + eputs ("\n"); if (pfoo) return 20; pfoo += one; - eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); + eputs ("pfoo="); + eputs (itoa (pfoo)); + eputs ("\n"); if (pfoo != foo_size) return 21; - eputs ("&one: "); eputs (itoa (&one)); eputs ("\n"); - eputs ("&two: "); eputs (itoa (&two)); eputs ("\n"); + eputs ("&one: "); + eputs (itoa (&one)); + eputs ("\n"); + eputs ("&two: "); + eputs (itoa (&two)); + eputs ("\n"); if (&one - 1 != &two) return 22; - struct foo* sym = foo_size + foo_size; + struct foo *sym = foo_size + foo_size; int i = sym + 16; - eputs ("i="); eputs (itoa (i)); eputs ("\n"); + eputs ("i="); + eputs (itoa (i)); + eputs ("\n"); if (i != foo_size_18) return 23; int d = 16; i = sym + d; - eputs ("i="); eputs (itoa (i)); eputs ("\n"); + eputs ("i="); + eputs (itoa (i)); + eputs ("\n"); if (i != foo_size_18) return 24; i = sym - 16; - eputs ("i="); eputs (itoa (i)); eputs ("\n"); + eputs ("i="); + eputs (itoa (i)); + eputs ("\n"); if (i != -foo_size_14) return 25; i = sym - d; - eputs ("i="); eputs (itoa (i)); eputs ("\n"); + eputs ("i="); + eputs (itoa (i)); + eputs ("\n"); if (i != -foo_size_14) return 26; - i = sym - (struct foo*)foo_size; - eputs ("i="); eputs (itoa (i)); eputs ("\n"); + i = sym - (struct foo *) foo_size; + eputs ("i="); + eputs (itoa (i)); + eputs ("\n"); if (i != 1) return 27; pfoo = sym + 1; pfoo -= sym; - eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); + eputs ("pfoo="); + eputs (itoa (pfoo)); + eputs ("\n"); if (pfoo != 1) return 28; diff --git a/scaffold/tests/77-pointer-assign.c b/scaffold/tests/77-pointer-assign.c index ad9a6008..6be1e60f 100644 --- a/scaffold/tests/77-pointer-assign.c +++ b/scaffold/tests/77-pointer-assign.c @@ -22,36 +22,38 @@ #include -struct baz { +struct baz +{ int i; int j; }; -struct foo { +struct foo +{ int **bar; }; void add0 (void *ptab) { - void **pp = *(void***)ptab; - bla: + void **pp = *(void ***) ptab; +bla: pp[0] = 0x11223344; } void add1 (void *ptab) { - void ***x = (void***)ptab; - bla: - *(void***)ptab = 0x22334455; + void ***x = (void ***) ptab; +bla: + *(void ***) ptab = 0x22334455; } void add2 (void *ptab) { - void ***x = (void***)ptab; - bla: + void ***x = (void ***) ptab; +bla: *x = 0x33445566; } @@ -64,19 +66,30 @@ main () int *p = &i; struct foo f; f.bar = &p; - eputs ("f.bar:"); eputs (itoa (f.bar)); eputs ("\n"); + eputs ("f.bar:"); + eputs (itoa (f.bar)); + eputs ("\n"); add0 (&f.bar); - eputs ("f.bar:"); eputs (itoa (*f.bar)); eputs ("\n"); - if (*f.bar != 0x11223344) return 1; + eputs ("f.bar:"); + eputs (itoa (*f.bar)); + eputs ("\n"); + if (*f.bar != 0x11223344) + return 1; add1 (&f.bar); - eputs ("f.bar:"); eputs (itoa (f.bar)); eputs ("\n"); - if (f.bar != 0x22334455) return 2; + eputs ("f.bar:"); + eputs (itoa (f.bar)); + eputs ("\n"); + if (f.bar != 0x22334455) + return 2; add2 (&f.bar); - eputs ("f.bar:"); eputs (itoa (f.bar)); eputs ("\n"); - if (f.bar != 0x33445566) return 3; + eputs ("f.bar:"); + eputs (itoa (f.bar)); + eputs ("\n"); + if (f.bar != 0x33445566) + return 3; hash_ident[0] = 10; *hash_ident = 0; @@ -84,11 +97,13 @@ main () struct baz b; b.i = b.j = 1; - if (b.i != 1) return 4; + if (b.i != 1) + return 4; struct baz *pb = &b; pb->i = pb->j = 1; - if (pb->i != 1) return 5; + if (pb->i != 1) + return 5; return 0; } diff --git a/scaffold/tests/78-union-struct.c b/scaffold/tests/78-union-struct.c index cd623b21..cb9cfb67 100644 --- a/scaffold/tests/78-union-struct.c +++ b/scaffold/tests/78-union-struct.c @@ -22,12 +22,14 @@ #include -struct foo { - int i; - void *p; +struct foo +{ + int i; + void *p; }; -union bar { +union bar +{ struct foo foo; }; @@ -40,7 +42,8 @@ main () bar.foo.p = "hallo"; union bar *pb = &bar; - if (pb->foo.i != 2) return 1; + if (pb->foo.i != 2) + return 1; return 0; } diff --git a/scaffold/tests/79-int-array-simple.c b/scaffold/tests/79-int-array-simple.c index a0579283..4e90010c 100644 --- a/scaffold/tests/79-int-array-simple.c +++ b/scaffold/tests/79-int-array-simple.c @@ -20,14 +20,14 @@ #include -int bla[2] = {0,-1}; +int bla[2] = { 0, -1 }; int main () { int *b = &bla; - int c[2] = {201, 211}; + int c[2] = { 201, 211 }; b[0] = 3; return 0; diff --git a/scaffold/tests/79-int-array.c b/scaffold/tests/79-int-array.c index bb696092..9684a0b8 100644 --- a/scaffold/tests/79-int-array.c +++ b/scaffold/tests/79-int-array.c @@ -30,8 +30,8 @@ struct foo struct foo f; -int bla[6] = {0,0,11223344, 55667788,0,0}; -int g_c[2] = {101, 111}; +int bla[6] = { 0, 0, 11223344, 55667788, 0, 0 }; +int g_c[2] = { 101, 111 }; int main () @@ -48,29 +48,45 @@ main () if (b[3] != 55667788) return 4; - eputs ("g_c[0]="); eputs (itoa (g_c[0])); eputs ("\n"); - eputs ("g_c[1]="); eputs (itoa (g_c[1])); eputs ("\n"); + eputs ("g_c[0]="); + eputs (itoa (g_c[0])); + eputs ("\n"); + eputs ("g_c[1]="); + eputs (itoa (g_c[1])); + eputs ("\n"); memcpy (&b[2], g_c, 2 * sizeof (int)); - eputs ("b[2]:"); eputs (itoa (b[2])); eputs ("\n"); + eputs ("b[2]:"); + eputs (itoa (b[2])); + eputs ("\n"); if (b[2] != 101) return 5; - eputs ("b[3]:"); eputs (itoa (b[3])); eputs ("\n"); + eputs ("b[3]:"); + eputs (itoa (b[3])); + eputs ("\n"); if (b[3] != 111) return 6; - int c[2] = {201, 211}; - eputs ("c[0]="); eputs (itoa (c[0])); eputs ("\n"); - eputs ("c[1]="); eputs (itoa (c[1])); eputs ("\n"); + int c[2] = { 201, 211 }; + eputs ("c[0]="); + eputs (itoa (c[0])); + eputs ("\n"); + eputs ("c[1]="); + eputs (itoa (c[1])); + eputs ("\n"); memcpy (&b[4], c, 2 * sizeof (int)); - eputs ("b[4]:"); eputs (itoa (b[4])); eputs ("\n"); + eputs ("b[4]:"); + eputs (itoa (b[4])); + eputs ("\n"); if (b[4] != 201) return 7; - eputs ("b[5]:"); eputs (itoa (b[5])); eputs ("\n"); + eputs ("b[5]:"); + eputs (itoa (b[5])); + eputs ("\n"); if (b[5] != 211) return 8; diff --git a/scaffold/tests/7a-struct-char-array.c b/scaffold/tests/7a-struct-char-array.c index 6bea556f..0c4b096a 100644 --- a/scaffold/tests/7a-struct-char-array.c +++ b/scaffold/tests/7a-struct-char-array.c @@ -22,11 +22,13 @@ #include #include -struct file { +struct file +{ char buffer[1]; }; -struct xfile { +struct xfile +{ char *buffer; }; @@ -152,8 +154,10 @@ main () eputs (file.buffer); memcpy (ps + 1, " ", 2); eputs (file.buffer); - eputs (itoa (ps[1])); eputs ("\n"); - eputs (itoa (((' ' << 8) + ' '))); eputs ("\n"); + eputs (itoa (ps[1])); + eputs ("\n"); + eputs (itoa (((' ' << 8) + ' '))); + eputs ("\n"); if (ps[1] != ((' ' << 8) + ' ')) return 40; if (p[4] != '4') @@ -163,8 +167,10 @@ main () eputs (file.buffer); ps[2] = ((' ' << 8) + ' '); eputs (file.buffer); - eputs (itoa (ps[2])); eputs ("\n"); - eputs (itoa (((' ' << 8) + ' '))); eputs ("\n"); + eputs (itoa (ps[2])); + eputs ("\n"); + eputs (itoa (((' ' << 8) + ' '))); + eputs ("\n"); if (ps[2] != ((' ' << 8) + ' ')) return 42; if (p[6] != '6') diff --git a/scaffold/tests/7b-struct-int-array-hello.c b/scaffold/tests/7b-struct-int-array-hello.c index 9ea1d444..6856a939 100644 --- a/scaffold/tests/7b-struct-int-array-hello.c +++ b/scaffold/tests/7b-struct-int-array-hello.c @@ -26,7 +26,7 @@ struct foo int b; }; -struct foo g_foo[2] = {0,1,2,3}; +struct foo g_foo[2] = { 0, 1, 2, 3 }; int diff --git a/scaffold/tests/7b-struct-int-array-pointer.c b/scaffold/tests/7b-struct-int-array-pointer.c index 0b770711..a5b4144c 100644 --- a/scaffold/tests/7b-struct-int-array-pointer.c +++ b/scaffold/tests/7b-struct-int-array-pointer.c @@ -25,7 +25,7 @@ struct bar int bar[4]; }; -struct bar g_bar = {101,102}; +struct bar g_bar = { 101, 102 }; int main () diff --git a/scaffold/tests/7b-struct-int-array.c b/scaffold/tests/7b-struct-int-array.c index bf8b66ed..d1cf93d9 100644 --- a/scaffold/tests/7b-struct-int-array.c +++ b/scaffold/tests/7b-struct-int-array.c @@ -26,14 +26,15 @@ struct foo int b; }; -struct foo g_foo[2] = {0,1,2,3}; +struct foo g_foo[2] = { 0, 1, 2, 3 }; struct bar { int bar[4]; }; -struct bar g_bar = {101,102}; +struct bar g_bar = { 101, 102 }; + typedef struct bar bar_struct; typedef struct bar foo_struct; @@ -50,7 +51,7 @@ main () return 4; void *p = &g_foo; - struct foo* pfoo = (((struct foo *)p) + 1); + struct foo *pfoo = (((struct foo *) p) + 1); if (pfoo->a != 2) return 5; if (pfoo->b != 3) @@ -64,7 +65,7 @@ main () if (*pi != 101) return 8; - struct bar bar = {0x22, 0x33}; + struct bar bar = { 0x22, 0x33 }; pi = &bar; if (*pi != 0x22) return 9; diff --git a/scaffold/tests/7c-dynarray.c b/scaffold/tests/7c-dynarray.c index a6406526..09712fc8 100644 --- a/scaffold/tests/7c-dynarray.c +++ b/scaffold/tests/7c-dynarray.c @@ -28,29 +28,32 @@ void add (void *ptab, int *nb_ptr, void *data) { - int nb, nb_alloc; - int **pp; + int nb, nb_alloc; + int **pp; - nb = *nb_ptr; - pp = *(void ***)ptab; - /* every power of two we double array size */ - if ((nb & (nb - 1)) == 0) { - if (!nb) - nb_alloc = 1; - else - nb_alloc = nb * 2; - pp = realloc (pp, nb_alloc * sizeof(void *)); - *(void***)ptab = pp; + nb = *nb_ptr; + pp = *(void ***) ptab; + /* every power of two we double array size */ + if ((nb & (nb - 1)) == 0) + { + if (!nb) + nb_alloc = 1; + else + nb_alloc = nb * 2; + pp = realloc (pp, nb_alloc * sizeof (void *)); + *(void ***) ptab = pp; } - pp[nb++] = data; - *nb_ptr = nb; + pp[nb++] = data; + *nb_ptr = nb; } -typedef struct file4 { +typedef struct file4 +{ char name[4]; } file4_struct; -typedef struct file12 { +typedef struct file12 +{ int foo; int bar; char name[4]; @@ -59,7 +62,8 @@ typedef struct file12 { //#define file file4 #define file file12 -struct state { +struct state +{ int bla; char **paths; int path_count; @@ -75,7 +79,7 @@ main () { struct state *s = &g_s; - char* file_name = "file-name"; + char *file_name = "file-name"; struct file *file; file = malloc (sizeof (struct file) + strlen (file_name)); @@ -85,30 +89,56 @@ main () char *path_name = "foo:bar:baz"; add (&s->paths, &s->path_count, path_name); - if (strcmp (*s->paths, path_name)) return 1; + if (strcmp (*s->paths, path_name)) + return 1; - eputs ("&PATHS="); eputs (itoa (&s->paths)); eputs ("\n"); - eputs ("&FILES="); eputs (itoa (&s->files)); eputs ("\n"); + eputs ("&PATHS="); + eputs (itoa (&s->paths)); + eputs ("\n"); + eputs ("&FILES="); + eputs (itoa (&s->files)); + eputs ("\n"); // struct file *fs; // eputs ("foo\n"); // fs = s->files[0]; struct file *fs = s->files[0]; - eputs ("add s= "); eputs (itoa (s)); eputs ("\n"); - eputs ("add fs= "); eputs (itoa (fs)); eputs ("\n"); - eputs ("&fs->[0]="); eputs (itoa (fs->name)); eputs ("\n"); - eputs ("fs->name="); eputs (fs->name); eputs ("\n"); + eputs ("add s= "); + eputs (itoa (s)); + eputs ("\n"); + eputs ("add fs= "); + eputs (itoa (fs)); + eputs ("\n"); + eputs ("&fs->[0]="); + eputs (itoa (fs->name)); + eputs ("\n"); + eputs ("fs->name="); + eputs (fs->name); + eputs ("\n"); - eputs ("ps= "); eputs (itoa (s->paths)); eputs ("\n"); - eputs ("*ps "); eputs (*s->paths); eputs ("\n"); + eputs ("ps= "); + eputs (itoa (s->paths)); + eputs ("\n"); + eputs ("*ps "); + eputs (*s->paths); + eputs ("\n"); - if (strcmp (fs->name, file_name)) return 2; + if (strcmp (fs->name, file_name)) + return 2; - eputs ("&fs->[0]="); eputs (itoa (fs->name)); eputs ("\n"); - eputs ("fs->name="); eputs (fs->name); eputs ("\n"); + eputs ("&fs->[0]="); + eputs (itoa (fs->name)); + eputs ("\n"); + eputs ("fs->name="); + eputs (fs->name); + eputs ("\n"); - eputs ("ps= "); eputs (itoa (s->paths)); eputs ("\n"); - eputs ("*ps "); eputs (*s->paths); eputs ("\n"); + eputs ("ps= "); + eputs (itoa (s->paths)); + eputs ("\n"); + eputs ("*ps "); + eputs (*s->paths); + eputs ("\n"); file = malloc (sizeof (struct file) + strlen (file_name)); @@ -119,28 +149,46 @@ main () struct file **pf = s->files; fs = pf[0]; eputs ("\n"); - eputs ("&fs0*= "); eputs (itoa (&pf[0])); eputs ("\n"); + eputs ("&fs0*= "); + eputs (itoa (&pf[0])); + eputs ("\n"); - eputs ("fs0*= "); eputs (itoa (fs)); eputs ("\n"); + eputs ("fs0*= "); + eputs (itoa (fs)); + eputs ("\n"); fs = s->files[0]; - eputs ("fs0*= "); eputs (itoa (fs)); eputs ("\n"); + eputs ("fs0*= "); + eputs (itoa (fs)); + eputs ("\n"); eputs ("\n"); pf = s->files; fs = pf[1]; - eputs ("&fs1*= "); eputs (itoa (&pf[1])); eputs ("\n"); - eputs ("fs1*= "); eputs (itoa (fs)); eputs ("\n"); - fs = s->files[1]; - eputs ("fs1*= "); eputs (itoa (fs)); eputs ("\n"); + eputs ("&fs1*= "); + eputs (itoa (&pf[1])); eputs ("\n"); - if (strcmp (fs->name, file_name)) return 3; + eputs ("fs1*= "); + eputs (itoa (fs)); + eputs ("\n"); + fs = s->files[1]; + eputs ("fs1*= "); + eputs (itoa (fs)); + eputs ("\n"); + eputs ("\n"); + if (strcmp (fs->name, file_name)) + return 3; fs = g_s.files[0]; - eputs ("gfs0*= "); eputs (itoa (fs)); eputs ("\n"); - fs = g_s.files[1]; - eputs ("gfs1*= "); eputs (itoa (fs)); eputs ("\n"); + eputs ("gfs0*= "); + eputs (itoa (fs)); eputs ("\n"); - if (strcmp (fs->name, file_name)) return 3; + fs = g_s.files[1]; + eputs ("gfs1*= "); + eputs (itoa (fs)); + eputs ("\n"); + eputs ("\n"); + if (strcmp (fs->name, file_name)) + return 3; return 0; diff --git a/scaffold/tests/7d-cast-char.c b/scaffold/tests/7d-cast-char.c index b7ae799f..6438b003 100644 --- a/scaffold/tests/7d-cast-char.c +++ b/scaffold/tests/7d-cast-char.c @@ -25,14 +25,18 @@ main () { char *s = "int"; char c = s[0]; - if (c != 'i') return 1; - int i = ((unsigned char *)s)[0]; - if (i != 'i') return 2; + if (c != 'i') + return 1; + int i = ((unsigned char *) s)[0]; + if (i != 'i') + return 2; c = s[1]; - if (c != 'n') return 3; - i = ((unsigned char *)s)[1]; - if (i != 'n') return 3; + if (c != 'n') + return 3; + i = ((unsigned char *) s)[1]; + if (i != 'n') + return 3; return 0; } diff --git a/scaffold/tests/7e-struct-array-access.c b/scaffold/tests/7e-struct-array-access.c index 41862439..09c66391 100644 --- a/scaffold/tests/7e-struct-array-access.c +++ b/scaffold/tests/7e-struct-array-access.c @@ -24,7 +24,8 @@ #include #include -struct symbol { +struct symbol +{ int len; char str[10]; //int len; @@ -33,13 +34,13 @@ struct symbol { struct symbol *list[2]; struct symbol s0; struct symbol s1; -struct symbol** plist; +struct symbol **plist; char * find0 () { - strcpy (s0.str, "foo"); - strcpy (s1.str, "bar"); + strcpy (s0.str, "foo"); + strcpy (s1.str, "bar"); list[0] = &s0; list[1] = &s1; //return s0.str; @@ -72,21 +73,30 @@ int main () { char *s = find0 (); - eputs (s); eputs ("\n"); - if (strcmp (s, "foo")) return 1; - if (strcmp (list[0]->str, "foo")) return 2; + eputs (s); + eputs ("\n"); + if (strcmp (s, "foo")) + return 1; + if (strcmp (list[0]->str, "foo")) + return 2; s = find1 (); - eputs (s); eputs ("\n"); - if (strcmp (s, "bar")) return 3; - if (strcmp (list[1]->str, "bar")) return 4; + eputs (s); + eputs ("\n"); + if (strcmp (s, "bar")) + return 3; + if (strcmp (list[1]->str, "bar")) + return 4; s = find2 (); - eputs (s); eputs ("\n"); - if (strcmp (s, "pbar")) return 5; + eputs (s); + eputs ("\n"); + if (strcmp (s, "pbar")) + return 5; list[1]->len = 2; - if (list[1]->len != 2) return 6; + if (list[1]->len != 2) + return 6; return 0; } diff --git a/scaffold/tests/7f-struct-pointer-arithmetic.c b/scaffold/tests/7f-struct-pointer-arithmetic.c index 6ddd9549..e5ec671d 100644 --- a/scaffold/tests/7f-struct-pointer-arithmetic.c +++ b/scaffold/tests/7f-struct-pointer-arithmetic.c @@ -26,11 +26,12 @@ struct foo; typedef struct foo foo_struct; -struct foo { +struct foo +{ //struct foo **foo; foo_struct **foo; }; - + struct foo g_foo[2]; int @@ -40,28 +41,49 @@ main () foo.foo = g_foo; void *p; void *q; - + p = &foo.foo[0]; q = foo.foo; - eputs ("f:"); eputs (itoa (foo.foo)); eputs ("\n"); - eputs ("p:"); eputs (itoa (p)); eputs ("\n"); - eputs ("q:"); eputs (itoa (q)); eputs ("\n"); - if (q != p) return 1; + eputs ("f:"); + eputs (itoa (foo.foo)); + eputs ("\n"); + eputs ("p:"); + eputs (itoa (p)); + eputs ("\n"); + eputs ("q:"); + eputs (itoa (q)); + eputs ("\n"); + if (q != p) + return 1; p = &foo.foo[1]; q = foo.foo + 1; - eputs ("f:"); eputs (itoa (foo.foo)); eputs ("\n"); - eputs ("p:"); eputs (itoa (p)); eputs ("\n"); - eputs ("q:"); eputs (itoa (q)); eputs ("\n"); - if (q != p) return 2; + eputs ("f:"); + eputs (itoa (foo.foo)); + eputs ("\n"); + eputs ("p:"); + eputs (itoa (p)); + eputs ("\n"); + eputs ("q:"); + eputs (itoa (q)); + eputs ("\n"); + if (q != p) + return 2; struct foo *pfoo = &foo; p = &pfoo->foo[1]; q = pfoo->foo + 1; - eputs ("f:"); eputs (itoa (pfoo->foo)); eputs ("\n"); - eputs ("p:"); eputs (itoa (p)); eputs ("\n"); - eputs ("q:"); eputs (itoa (q)); eputs ("\n"); - if (q != p) return 3; + eputs ("f:"); + eputs (itoa (pfoo->foo)); + eputs ("\n"); + eputs ("p:"); + eputs (itoa (p)); + eputs ("\n"); + eputs ("q:"); + eputs (itoa (q)); + eputs ("\n"); + if (q != p) + return 3; return 0; } diff --git a/scaffold/tests/7g-struct-byte-word-field.c b/scaffold/tests/7g-struct-byte-word-field.c index 6336a2bd..435295b5 100644 --- a/scaffold/tests/7g-struct-byte-word-field.c +++ b/scaffold/tests/7g-struct-byte-word-field.c @@ -23,7 +23,8 @@ #include #include -struct option { +struct option +{ char const *name; uint8_t index; uint16_t flags; @@ -33,24 +34,32 @@ struct option { int main () { - struct option h = {"help", 0, 10, 1}; - struct option o = {"output", 1, 11, 1}; - struct option v = {"version", 0, 0, 1}; + struct option h = { "help", 0, 10, 1 }; + struct option o = { "output", 1, 11, 1 }; + struct option v = { "version", 0, 0, 1 }; - if (strcmp (h.name, "help")) return 1; - if (h.index != 0) return 2; - if (h.flags != 10) return 3; + if (strcmp (h.name, "help")) + return 1; + if (h.index != 0) + return 2; + if (h.flags != 10) + return 3; struct option *p = &o; - if (strcmp (p->name, "output")) return 4; - if (p->index != 1) return 5; - if (p->flags != 11) return 6; + if (strcmp (p->name, "output")) + return 4; + if (p->index != 1) + return 5; + if (p->flags != 11) + return 6; p = &v; v.index = 2; p->flags = 12; - if (v.index != 2) return 7; - if (v.flags != 12) return 8; + if (v.index != 2) + return 7; + if (v.flags != 12) + return 8; return 0; } diff --git a/scaffold/tests/7h-struct-assign.c b/scaffold/tests/7h-struct-assign.c index 03f13162..d4ebcf35 100644 --- a/scaffold/tests/7h-struct-assign.c +++ b/scaffold/tests/7h-struct-assign.c @@ -21,12 +21,14 @@ #include #include -struct string { +struct string +{ char *str; int len; }; -typedef struct biggie { +typedef struct biggie +{ int a; int b; int c; @@ -34,7 +36,8 @@ typedef struct biggie { int len; } biggie; -struct other { +struct other +{ struct biggie big; }; @@ -45,94 +48,132 @@ struct biggie tab[2]; int main () { - struct string s = {"hallo"}; + struct string s = { "hallo" }; s.len = strlen (s.str); - eputs (s.str); eputs ("\n"); + eputs (s.str); + eputs ("\n"); struct string t; t = s; - eputs (t.str); eputs ("\n"); - if (t.len != s.len) return 1; - if (strcmp (t.str, s.str)) return 2; + eputs (t.str); + eputs ("\n"); + if (t.len != s.len) + return 1; + if (strcmp (t.str, s.str)) + return 2; g_t = s; - eputs (g_t.str); eputs ("\n"); - if (g_t.len != s.len) return 3; - if (strcmp (g_t.str, s.str)) return 4; + eputs (g_t.str); + eputs ("\n"); + if (g_t.len != s.len) + return 3; + if (strcmp (g_t.str, s.str)) + return 4; struct biggie b; b.str = "hello"; b.len = strlen (b.str); - eputs (b.str); eputs ("\n"); + eputs (b.str); + eputs ("\n"); struct biggie tb; tb = b; - eputs (tb.str); eputs ("\n"); - if (tb.len != b.len) return 5; - if (strcmp (tb.str, b.str)) return 6; + eputs (tb.str); + eputs ("\n"); + if (tb.len != b.len) + return 5; + if (strcmp (tb.str, b.str)) + return 6; b.str = "bye"; b.len = strlen (b.str); - eputs (b.str); eputs ("\n"); + eputs (b.str); + eputs ("\n"); //struct biggie *pb = &tb; biggie *pb = &tb; *pb = b; - eputs (tb.str); eputs ("\n"); - if (tb.len != b.len) return 7; - if (strcmp (tb.str, b.str)) return 8; + eputs (tb.str); + eputs ("\n"); + if (tb.len != b.len) + return 7; + if (strcmp (tb.str, b.str)) + return 8; tb.str = "there"; tb.len = strlen (tb.str); b = *pb; - eputs (b.str); eputs ("\n"); - if (b.len != tb.len) return 9; - if (strcmp (b.str, tb.str)) return 10; + eputs (b.str); + eputs ("\n"); + if (b.len != tb.len) + return 9; + if (strcmp (b.str, tb.str)) + return 10; char **x = &b.str; char *p; p = *x; struct other o; - struct other* po = &o; + struct other *po = &o; po->big = b; - eputs (o.big.str); eputs ("\n"); - if (o.big.len != b.len) return 13; - if (strcmp (o.big.str, b.str)) return 14; + eputs (o.big.str); + eputs ("\n"); + if (o.big.len != b.len) + return 13; + if (strcmp (o.big.str, b.str)) + return 14; po->big = *pb; - eputs (o.big.str); eputs ("\n"); - if (o.big.len != b.len) return 15; - if (strcmp (o.big.str, b.str)) return 16; + eputs (o.big.str); + eputs ("\n"); + if (o.big.len != b.len) + return 15; + if (strcmp (o.big.str, b.str)) + return 16; b.str = "* = *"; b.len = strlen (b.str); - eputs (b.str); eputs ("\n"); + eputs (b.str); + eputs ("\n"); struct biggie *q = tab; pb = &b; *q++ = *pb; - eputs (tab[0].str); eputs ("\n"); - if (tab[0].len != b.len) return 17; - if (strcmp (tab[0].str, b.str)) return 18; + eputs (tab[0].str); + eputs ("\n"); + if (tab[0].len != b.len) + return 17; + if (strcmp (tab[0].str, b.str)) + return 18; tab[1] = tab[0]; - eputs (tab[1].str); eputs ("\n"); - if (tab[1].len != b.len) return 19; - if (strcmp (tab[1].str, b.str)) return 20; + eputs (tab[1].str); + eputs ("\n"); + if (tab[1].len != b.len) + return 19; + if (strcmp (tab[1].str, b.str)) + return 20; tab[0].str = "burp"; tab[0].len = strlen (tab[1].str); - eputs (tab[0].str); eputs ("\n"); + eputs (tab[0].str); + eputs ("\n"); b = tab[0]; - eputs (b.str); eputs ("\n"); - if (b.len != tab[0].len) return 21; - if (strcmp (b.str, tab[0].str)) return 22; + eputs (b.str); + eputs ("\n"); + if (b.len != tab[0].len) + return 21; + if (strcmp (b.str, tab[0].str)) + return 22; tab[1] = b; - eputs (tab[1].str); eputs ("\n"); - if (tab[1].len != b.len) return 23; - if (strcmp (tab[1].str, b.str)) return 24; + eputs (tab[1].str); + eputs ("\n"); + if (tab[1].len != b.len) + return 23; + if (strcmp (tab[1].str, b.str)) + return 24; return 0; } diff --git a/scaffold/tests/7i-struct-struct-simple.c b/scaffold/tests/7i-struct-struct-simple.c index a4a46af0..de8b331c 100644 --- a/scaffold/tests/7i-struct-struct-simple.c +++ b/scaffold/tests/7i-struct-struct-simple.c @@ -36,7 +36,7 @@ struct foo int main () { - struct foo f = {1,2}; + struct foo f = { 1, 2 }; return 0; } diff --git a/scaffold/tests/7i-struct-struct.c b/scaffold/tests/7i-struct-struct.c index 00518666..381bce90 100644 --- a/scaffold/tests/7i-struct-struct.c +++ b/scaffold/tests/7i-struct-struct.c @@ -37,7 +37,8 @@ struct foo struct anon { - struct { + struct + { int bar; int baz; }; @@ -47,21 +48,29 @@ struct anon int main () { - struct foo f = {0,1,2}; + struct foo f = { 0, 1, 2 }; f.s.baz = 2; - oputs ("f.s.bar="); oputs (itoa (f.s.bar)); oputs ("\n"); + oputs ("f.s.bar="); + oputs (itoa (f.s.bar)); + oputs ("\n"); if (f.s.bar != 1) return 1; - oputs ("f.s.baz="); oputs (itoa (f.s.baz)); oputs ("\n"); + oputs ("f.s.baz="); + oputs (itoa (f.s.baz)); + oputs ("\n"); if (f.s.baz != 2) return 2; - struct anon a = {3,4}; + struct anon a = { 3, 4 }; a.baz = 4; - oputs ("a.bar="); oputs (itoa (a.bar)); oputs ("\n"); + oputs ("a.bar="); + oputs (itoa (a.bar)); + oputs ("\n"); if (a.bar != 3) return 3; - oputs ("a.baz="); oputs (itoa (a.baz)); oputs ("\n"); + oputs ("a.baz="); + oputs (itoa (a.baz)); + oputs ("\n"); if (a.baz != 4) return 4; diff --git a/scaffold/tests/7k-empty-for.c b/scaffold/tests/7k-empty-for.c index abfb078a..deaced1c 100644 --- a/scaffold/tests/7k-empty-for.c +++ b/scaffold/tests/7k-empty-for.c @@ -24,7 +24,7 @@ main () int i = 1; for (;;) if (!i--) - break; + break; return i + 1; } diff --git a/scaffold/tests/7k-for-each-elem-simple.c b/scaffold/tests/7k-for-each-elem-simple.c index 7f0e3c1b..2321dbf2 100644 --- a/scaffold/tests/7k-for-each-elem-simple.c +++ b/scaffold/tests/7k-for-each-elem-simple.c @@ -25,15 +25,16 @@ struct sym { - char* name; + char *name; int index; }; -struct sym tab[1] = {"foo", 1}; +struct sym tab[1] = { "foo", 1 }; int main () { - eputs (tab[0].name); eputs ("\n"); + eputs (tab[0].name); + eputs ("\n"); return 0; } diff --git a/scaffold/tests/7k-for-each-elem.c b/scaffold/tests/7k-for-each-elem.c index c963fcb3..660bb1b3 100644 --- a/scaffold/tests/7k-for-each-elem.c +++ b/scaffold/tests/7k-for-each-elem.c @@ -28,12 +28,12 @@ struct section struct sym { - char* name; + char *name; int index; }; -struct sym tab3[3] = {"foo", 0, "bar", 1, "baz", 2}; -struct sym tab[] = {"foo", 0, "bar", 1, "baz", 2}; +struct sym tab3[3] = { "foo", 0, "bar", 1, "baz", 2 }; +struct sym tab[] = { "foo", 0, "bar", 1, "baz", 2 }; struct section section; @@ -55,32 +55,44 @@ main () int sym_size = 12; #endif - struct sym* p; + struct sym *p; p = tab3; section.data = tab; section.offset = 24; int size = sizeof (struct sym); - eputs ("size="); eputs (itoa (size)); eputs ("\n"); + eputs ("size="); + eputs (itoa (size)); + eputs ("\n"); if (size != sym_size) return 1; - struct section* psection = §ion; - p = (struct sym*)psection->data + 1; - struct sym* q = tab; - int i = (int)p; - i -= (int)q; - eputs ("diff="); eputs (itoa (i)); eputs ("\n"); + struct section *psection = §ion; + p = (struct sym *) psection->data + 1; + struct sym *q = tab; + int i = (int) p; + i -= (int) q; + eputs ("diff="); + eputs (itoa (i)); + eputs ("\n"); if (i != sym_size) return 2; - for_each_elem(psection, 1, p, struct section) { - eputs ("i="); eputs (itoa (p->index)); - eputs (" name="); eputs (p->name); eputs ("\n"); + for_each_elem (psection, 1, p, struct section) + { + eputs ("i="); + eputs (itoa (p->index)); + eputs (" name="); + eputs (p->name); + eputs ("\n"); } - for_each_elem2(psection, 1, p, struct section) { - eputs ("i="); eputs (itoa (p->index)); - eputs (" name="); eputs (p->name); eputs ("\n"); + for_each_elem2 (psection, 1, p, struct section) + { + eputs ("i="); + eputs (itoa (p->index)); + eputs (" name="); + eputs (p->name); + eputs ("\n"); } return 0; diff --git a/scaffold/tests/7l-struct-any-size-array.c b/scaffold/tests/7l-struct-any-size-array.c index 9c48f077..af3dbfdf 100644 --- a/scaffold/tests/7l-struct-any-size-array.c +++ b/scaffold/tests/7l-struct-any-size-array.c @@ -58,7 +58,10 @@ main () p = &tab14; for (int i = 0; i < sizeof (struct foo13) * 2; i++) { - if (i < 10) eputs (" "); eputs (itoa (i)); eputs (": "); + if (i < 10) + eputs (" "); + eputs (itoa (i)); + eputs (": "); eputs (itoa (p[i])); eputs ("\n"); } @@ -79,7 +82,10 @@ main () p = &tab16; for (int i = 0; i < sizeof (struct foo16) * 2; i++) { - if (i < 10) eputs (" "); eputs (itoa (i)); eputs (": "); + if (i < 10) + eputs (" "); + eputs (itoa (i)); + eputs (": "); eputs (itoa (p[i])); eputs ("\n"); } diff --git a/scaffold/tests/7m-struct-char-array-assign.c b/scaffold/tests/7m-struct-char-array-assign.c index 29247904..06d2783d 100644 --- a/scaffold/tests/7m-struct-char-array-assign.c +++ b/scaffold/tests/7m-struct-char-array-assign.c @@ -20,7 +20,8 @@ #include -struct file { +struct file +{ char *ptr; char buffer[20]; }; @@ -36,7 +37,8 @@ main () eputs ("***\n"); f.ptr[1] = 'X'; - eputs (f.ptr); eputs ("\n"); + eputs (f.ptr); + eputs ("\n"); return 0; } diff --git a/scaffold/tests/7n-struct-struct-array.c b/scaffold/tests/7n-struct-struct-array.c index d2f3444a..73a44598 100644 --- a/scaffold/tests/7n-struct-struct-array.c +++ b/scaffold/tests/7n-struct-struct-array.c @@ -25,12 +25,14 @@ #include #include -typedef struct file { +typedef struct file +{ char name[10]; } file_struct; #define STACK_SIZE 2 -struct state { +struct state +{ int bla; file_struct *stack[STACK_SIZE]; char buf[100]; @@ -48,56 +50,70 @@ main () s.stack_ptr = s.stack; ps->stack_ptr = ps->stack; - eputs ("ps->stack="); eputs (itoa (ps->stack)); eputs ("\n"); + eputs ("ps->stack="); + eputs (itoa (ps->stack)); + eputs ("\n"); eputs ("1\n"); - if (ps->stack_ptr >= ps->stack + STACK_SIZE) return 1; + if (ps->stack_ptr >= ps->stack + STACK_SIZE) + return 1; eputs ("2\n"); - struct file f = {"first.h"}; -#if 0 //__MESC__ + struct file f = { "first.h" }; +#if 0 //__MESC__ strcpy (f.name, "first.h"); #endif - eputs (f.name); eputs ("\n"); + eputs (f.name); + eputs ("\n"); *ps->stack_ptr = &f; eputs ("3\n"); ++ps->stack_ptr; - eputs ("s.stack_ptr -stack ="); eputs (itoa (ps->stack_ptr - ps->stack)); eputs ("\n"); + eputs ("s.stack_ptr -stack ="); + eputs (itoa (ps->stack_ptr - ps->stack)); + eputs ("\n"); eputs ("4\n"); - for (file_struct **p = ps->stack; p < ps->stack_ptr; p++) + for (file_struct ** p = ps->stack; p < ps->stack_ptr; p++) { - eputs ((*p)->name); eputs ("\n"); + eputs ((*p)->name); + eputs ("\n"); } eputs ("5\n"); int i; i = ps->stack_ptr - ps->stack + STACK_SIZE; - eputs ("i="); eputs (itoa (i)); eputs ("\n"); + eputs ("i="); + eputs (itoa (i)); + eputs ("\n"); - if (ps->stack_ptr >= ps->stack + STACK_SIZE) return 2; + if (ps->stack_ptr >= ps->stack + STACK_SIZE) + return 2; eputs ("6\n"); - struct file f2 = {"second.h"}; -#if 0//__MESC__ + struct file f2 = { "second.h" }; +#if 0 //__MESC__ strcpy (f2.name, "second.h"); #endif *ps->stack_ptr = &f2; eputs ("7\n"); ++ps->stack_ptr; - eputs ("s.stack_ptr -stack ="); eputs (itoa (ps->stack_ptr - ps->stack)); eputs ("\n"); + eputs ("s.stack_ptr -stack ="); + eputs (itoa (ps->stack_ptr - ps->stack)); + eputs ("\n"); - for (file_struct **p = ps->stack; p < ps->stack_ptr; p++) + for (file_struct ** p = ps->stack; p < ps->stack_ptr; p++) { - eputs ((*p)->name); eputs ("\n"); + eputs ((*p)->name); + eputs ("\n"); } - if (ps->stack_ptr >= ps->stack + STACK_SIZE) return 0; - struct file f3 = {"third.h"}; + if (ps->stack_ptr >= ps->stack + STACK_SIZE) + return 0; + struct file f3 = { "third.h" }; *ps->stack_ptr = &f3; ++ps->stack_ptr; return 3; diff --git a/scaffold/tests/7o-struct-pre-post-simple.c b/scaffold/tests/7o-struct-pre-post-simple.c index e93b930f..23b65813 100644 --- a/scaffold/tests/7o-struct-pre-post-simple.c +++ b/scaffold/tests/7o-struct-pre-post-simple.c @@ -20,14 +20,23 @@ #include -struct info {int flag;}; -struct foo {int length; char* string; struct info info;}; -struct foo stack[] = {{3, "foo", {11}},{4, "baar", {12}}}; +struct info +{ + int flag; +}; +struct foo +{ + int length; + char *string; + struct info info; +}; +struct foo stack[] = { {3, "foo", {11}}, {4, "baar", {12}} }; int main () { - oputs (stack[1].string); oputs ("\n"); + oputs (stack[1].string); + oputs ("\n"); return 0; } diff --git a/scaffold/tests/7o-struct-pre-post.c b/scaffold/tests/7o-struct-pre-post.c index 68a8e464..e7fb9101 100644 --- a/scaffold/tests/7o-struct-pre-post.c +++ b/scaffold/tests/7o-struct-pre-post.c @@ -20,16 +20,26 @@ #include -struct info {int flag;}; -struct foo {int length; char* string; struct info info;}; -struct foo stack[] = {{3, "foo", {11}},{4, "baar", {12}}}; +struct info +{ + int flag; +}; +struct foo +{ + int length; + char *string; + struct info info; +}; +struct foo stack[] = { {3, "foo", {11}}, {4, "baar", {12}} }; int main () { - oputs (stack[0].string); oputs ("\n"); - oputs (stack[1].string); oputs ("\n"); - struct foo* top = &stack[1]; + oputs (stack[0].string); + oputs ("\n"); + oputs (stack[1].string); + oputs ("\n"); + struct foo *top = &stack[1]; int i; int j; i = (top--)->info.flag; diff --git a/scaffold/tests/7p-struct-cast.c b/scaffold/tests/7p-struct-cast.c index 128c6fa2..08e0b52d 100644 --- a/scaffold/tests/7p-struct-cast.c +++ b/scaffold/tests/7p-struct-cast.c @@ -18,18 +18,22 @@ * along with GNU Mes. If not, see . */ -struct foo {int length; char* string;}; +struct foo +{ + int length; + char *string; +}; int main () { - struct foo f = {3, "foo"}; + struct foo f = { 3, "foo" }; struct foo *pf = &f; - char *p = (char*)&f; + char *p = (char *) &f; int i = 0; - i = ((struct foo*)p)->length; + i = ((struct foo *) p)->length; i = 0; - i = ((struct foo*)(p + i))->length; + i = ((struct foo *) (p + i))->length; return i - 3; } diff --git a/scaffold/tests/7q-bit-field-simple.c b/scaffold/tests/7q-bit-field-simple.c index 6711ba57..2efd5084 100644 --- a/scaffold/tests/7q-bit-field-simple.c +++ b/scaffold/tests/7q-bit-field-simple.c @@ -20,11 +20,7 @@ struct bits { - int - one: 1, - two : 1, - four: 1, - eightsixteen: 2; + int one:1, two:1, four:1, eightsixteen:2; }; union foo diff --git a/scaffold/tests/7q-bit-field.c b/scaffold/tests/7q-bit-field.c index d12595b1..05fb51db 100644 --- a/scaffold/tests/7q-bit-field.c +++ b/scaffold/tests/7q-bit-field.c @@ -20,11 +20,7 @@ struct bits { - int - one: 1, - two : 1, - four: 1, - eightsixteen: 2; + int one:1, two:1, four:1, eightsixteen:2; }; union foo diff --git a/scaffold/tests/7r-sign-extend.c b/scaffold/tests/7r-sign-extend.c index d9460d10..08a4ec02 100644 --- a/scaffold/tests/7r-sign-extend.c +++ b/scaffold/tests/7r-sign-extend.c @@ -19,7 +19,10 @@ */ char global_c = -1; -struct foo {char type;}; +struct foo +{ + char type; +}; int main () { @@ -38,7 +41,7 @@ main () { char c = -1; - int ints[2] = {c, 0}; + int ints[2] = { c, 0 }; if (ints[0] != -1) return 3; } @@ -58,7 +61,7 @@ main () } { - char a[2] = {-1, -129}; + char a[2] = { -1, -129 }; int i = a[0]; if (i != -1) return 6; @@ -67,7 +70,7 @@ main () } { - struct foo f = {-1}; + struct foo f = { -1 }; int i = f.type; if (i != -1) return 8; @@ -88,7 +91,7 @@ main () { int i = -129; - i = (char)i; + i = (char) i; if (i != 127) return 11; } diff --git a/scaffold/tests/7s-struct-short.c b/scaffold/tests/7s-struct-short.c index c6b06105..53621aef 100644 --- a/scaffold/tests/7s-struct-short.c +++ b/scaffold/tests/7s-struct-short.c @@ -31,11 +31,12 @@ struct bar char bar; }; -struct foo global_f = {0, 11, 22}; -struct bar global_b = {11}; +struct foo global_f = { 0, 11, 22 }; +struct bar global_b = { 11 }; + int i = 0x11223344; -struct foo foes[2] = {{0, 1, 2}, {0, 3, 4}}; +struct foo foes[2] = { {0, 1, 2}, {0, 3, 4} }; int main () @@ -46,7 +47,7 @@ main () if (global_f.baz != 22) return 2; - struct foo f = {0, 44, 55}; + struct foo f = { 0, 44, 55 }; if (f.bar != 44) return 3; diff --git a/scaffold/tests/7t-function-destruct.c b/scaffold/tests/7t-function-destruct.c index 1b6945cc..e06a545b 100644 --- a/scaffold/tests/7t-function-destruct.c +++ b/scaffold/tests/7t-function-destruct.c @@ -23,8 +23,8 @@ struct foo int bar; }; -struct foo* -test (struct foo* f) +struct foo * +test (struct foo *f) { void (*fun) () = test; return f; @@ -33,7 +33,7 @@ test (struct foo* f) int main () { - struct foo f = {1}; + struct foo f = { 1 }; int i = test (&f)->bar; return test (&f)->bar - i; } diff --git a/scaffold/tests/7u-struct-func.c b/scaffold/tests/7u-struct-func.c index 9e88b2db..62443ece 100644 --- a/scaffold/tests/7u-struct-func.c +++ b/scaffold/tests/7u-struct-func.c @@ -32,9 +32,9 @@ bar (int i) int main () { - struct foo f = {&bar}; + struct foo f = { &bar }; int i = f.func (2); - if (i !=1) + if (i != 1) return 1; return 0; diff --git a/scaffold/tests/7u-struct-size10.c b/scaffold/tests/7u-struct-size10.c index bb011115..d3b2418e 100644 --- a/scaffold/tests/7u-struct-size10.c +++ b/scaffold/tests/7u-struct-size10.c @@ -22,15 +22,15 @@ struct foo { - char *s; + char *s; #if __i386__ - long bar; + long bar; #endif - char baz; - char bla; + char baz; + char bla; }; -char g_arena[40] = {0}; +char g_arena[40] = { 0 }; int main () diff --git a/scaffold/tests/7u-vstack.c b/scaffold/tests/7u-vstack.c index fe345288..170c7cf1 100644 --- a/scaffold/tests/7u-vstack.c +++ b/scaffold/tests/7u-vstack.c @@ -28,7 +28,8 @@ struct foo #define VSTACK_SIZE 2 -struct foo __vstack[1+/*to make bcheck happy*/ VSTACK_SIZE] = {1,2,3,4}; +struct foo __vstack[1 + /*to make bcheck happy */ VSTACK_SIZE] = { 1, 2, 3, 4 }; + #define vstack (__vstack + 1) int diff --git a/scaffold/tests/82-define.c b/scaffold/tests/82-define.c index 3a55f23c..b25ce3a6 100644 --- a/scaffold/tests/82-define.c +++ b/scaffold/tests/82-define.c @@ -19,4 +19,8 @@ */ #define A AA AB AC AD AE AF AG AH AI AJ AK AL AM AN AO AP AQ AR AS AT AU AV AW AX AY AZ BA BB BC BD BE BF BG BH BI BJ BK BL BM BN BO BP BQ BR BS BT BU BV BW BX BY BZ CA CB CC CD CE CF CG CH CI CJ CK CL CM CN CO CP CQ CR CS CT CU CV CW CX CY CZ DA DB DC DD DE DF DG DH DI DJ DK DL DM DN DO DP -int main () { return 0; } +int +main () +{ + return 0; +} diff --git a/scaffold/tests/83-heterogenoous-init.c b/scaffold/tests/83-heterogenoous-init.c index f565b888..a2165d2c 100644 --- a/scaffold/tests/83-heterogenoous-init.c +++ b/scaffold/tests/83-heterogenoous-init.c @@ -23,7 +23,7 @@ int foo[2], *bar; int main () { - bar = foo+1; + bar = foo + 1; foo[0] = 1; *bar = 1; return *foo - bar[0]; diff --git a/scaffold/tests/84-struct-field-list.c b/scaffold/tests/84-struct-field-list.c index ffd03e00..b508bc8b 100644 --- a/scaffold/tests/84-struct-field-list.c +++ b/scaffold/tests/84-struct-field-list.c @@ -37,8 +37,8 @@ struct bar int main () { - struct foo f = {0, 0, 0, 0}; - struct foo g = {1, 0, 0, 0}; + struct foo f = { 0, 0, 0, 0 }; + struct foo g = { 1, 0, 0, 0 }; f.j = &f.i; g.j = &g.i; f.bar = &f; diff --git a/scaffold/tests/85-sizeof.c b/scaffold/tests/85-sizeof.c index 6a8e652c..84ce0b9e 100644 --- a/scaffold/tests/85-sizeof.c +++ b/scaffold/tests/85-sizeof.c @@ -53,7 +53,9 @@ main () return 1; if (sizeof (**p) != 1) return 2; - oputs ("size: "); oputs (itoa (sizeof (struct foo))); oputs ("\n"); + oputs ("size: "); + oputs (itoa (sizeof (struct foo))); + oputs ("\n"); if (sizeof (struct foo) != 20) return 3; struct foo f; diff --git a/scaffold/tests/90-goto-var.c b/scaffold/tests/90-goto-var.c index d03aeb72..a8baf5d8 100644 --- a/scaffold/tests/90-goto-var.c +++ b/scaffold/tests/90-goto-var.c @@ -24,7 +24,7 @@ main () static void *lbl = &&lbl_b; goto *lbl; - lbl_a: +lbl_a: return 1; lbl_b: return 0; diff --git a/scaffold/tests/91-goto-array.c b/scaffold/tests/91-goto-array.c index a8dafa7f..0a44d7a2 100644 --- a/scaffold/tests/91-goto-array.c +++ b/scaffold/tests/91-goto-array.c @@ -20,33 +20,35 @@ #include -int main(void) { - static void *lbls[] = { &&lbl_h, &&lbl_e, &&lbl_l, &&lbl_l, &&lbl_o, &&lbl_quit }; - static void **lbl = lbls; +int +main (void) +{ + static void *lbls[] = { &&lbl_h, &&lbl_e, &&lbl_l, &&lbl_l, &&lbl_o, &&lbl_quit }; + static void **lbl = lbls; - goto **lbl; + goto **lbl; lbl_e: - printf("e"); - lbl++; - goto **lbl; + printf ("e"); + lbl++; + goto **lbl; lbl_o: - printf("o"); - lbl++; - goto **lbl; + printf ("o"); + lbl++; + goto **lbl; lbl_h: - printf("h"); - lbl++; - goto **lbl; + printf ("h"); + lbl++; + goto **lbl; lbl_l: - printf("l"); - lbl++; - goto **lbl; + printf ("l"); + lbl++; + goto **lbl; lbl_quit: - puts(""); - return 0; + puts (""); + return 0; } diff --git a/scaffold/tests/a0-call-trunc-char.c b/scaffold/tests/a0-call-trunc-char.c index e00172c5..bacd87d8 100644 --- a/scaffold/tests/a0-call-trunc-char.c +++ b/scaffold/tests/a0-call-trunc-char.c @@ -23,7 +23,9 @@ int f (unsigned char x) { - eputs ("x="); eputs (itoa (x)); eputs ("\n"); + eputs ("x="); + eputs (itoa (x)); + eputs ("\n"); return x; } @@ -31,7 +33,7 @@ int main () { unsigned int x = -1; - x = f(x); + x = f (x); if (x != 255) return 1; return 0; diff --git a/scaffold/tests/a0-call-trunc-int.c b/scaffold/tests/a0-call-trunc-int.c index b21dd0f9..106624ea 100644 --- a/scaffold/tests/a0-call-trunc-int.c +++ b/scaffold/tests/a0-call-trunc-int.c @@ -23,7 +23,9 @@ long f (unsigned int x) { - eputs ("x="); eputs (utoa (x)); eputs ("\n"); + eputs ("x="); + eputs (utoa (x)); + eputs ("\n"); return x; } @@ -32,7 +34,9 @@ main () { unsigned long x = -1; x = f (x); - eputs ("x="); eputs (ultoa (x)); eputs ("\n"); + eputs ("x="); + eputs (ultoa (x)); + eputs ("\n"); if (x != 0xffffffff) return 1; return 0; diff --git a/scaffold/tests/a0-call-trunc-short.c b/scaffold/tests/a0-call-trunc-short.c index 13755c90..81d45055 100644 --- a/scaffold/tests/a0-call-trunc-short.c +++ b/scaffold/tests/a0-call-trunc-short.c @@ -23,7 +23,9 @@ int f (unsigned short x) { - eputs ("x="); eputs (itoa (x)); eputs ("\n"); + eputs ("x="); + eputs (itoa (x)); + eputs ("\n"); return x; } @@ -31,7 +33,7 @@ int main () { unsigned int x = -1; - x = f(x); + x = f (x); if (x != 65535) return 1; return 0; diff --git a/scaffold/tests/t.c b/scaffold/tests/t.c index acb462ff..13149857 100644 --- a/scaffold/tests/t.c +++ b/scaffold/tests/t.c @@ -19,29 +19,57 @@ */ -int puts (char const*); +int puts (char const *); #include char global_arena[10]; int global_i = 1; int global_unitialized; -char* global_string = "foo"; +char *global_string = "foo"; char global_array[8] = "XXX"; char *global_chars = global_array; typedef int SCM; -enum type_t {TCHAR}; -char *env[] = {"foo", "bar", "baz", 0}; -char *list[2] = {"foo\n", "bar\n"}; +enum type_t +{ TCHAR }; +char *env[] = { "foo", "bar", "baz", 0 }; +char *list[2] = { "foo\n", "bar\n" }; + +struct foo +{ + int length; + char *string; +}; +struct foo g_f = { 3, "foo" }; -struct foo {int length; char* string;}; -struct foo g_f = {3, "foo"}; struct foo *g_g = &g_f; struct foo g_foes[2]; int g_foe; -struct anon {struct {int bar; int baz;};}; -struct anion {union {int foo; int bar;}; union {int baz; int bla;};}; +struct anon +{ + struct + { + int bar; + int baz; + }; +}; +struct anion +{ + union + { + int foo; + int bar; + }; + union + { + int baz; + int bla; + }; +}; -struct here {int and;} there; +struct here +{ + int and; +} there; typedef int int_array_t[1]; int_array_t bar; @@ -57,17 +85,17 @@ struct nest } bar; int i; enum baz - { - bla - } baz; + { + bla + } baz; enum - { - blub = 33, - } blub; + { + blub = 33, + } blub; }; int -test (struct foo* p) +test (struct foo *p) { struct foo *g = &g_f; g[0].length = 0; @@ -75,13 +103,13 @@ test (struct foo* p) } int -next_main (int argc, char* argv[]) +next_main (int argc, char *argv[]) { return 0; } int -main (int argc, char* argv[]) +main (int argc, char *argv[]) { int i; int j = 1; @@ -123,12 +151,12 @@ main (int argc, char* argv[]) return 16; if (strcmp (g_f.string, "foo")) return 17; - struct foo g = {4, "baar"}; + struct foo g = { 4, "baar" }; if (g.length != 4) return 18; if (strcmp (g.string, "baar")) return 19; - struct foo f = {3, "foo"}; + struct foo f = { 3, "foo" }; g_foes[0] = f; g_foes[1] = f; if (g_foe) @@ -140,23 +168,31 @@ main (int argc, char* argv[]) if (strcmp (strings[1], "two\n")) return 21; p = list; - struct anon a = {3,4}; - eputs ("bar:"); eputs (itoa (a.bar)); eputs ("\n"); - eputs ("baz:"); eputs (itoa (a.baz)); eputs ("\n"); + struct anon a = { 3, 4 }; + eputs ("bar:"); + eputs (itoa (a.bar)); + eputs ("\n"); + eputs ("baz:"); + eputs (itoa (a.baz)); + eputs ("\n"); if (a.bar != 3) return 22; if (a.baz != 4) return 23; - struct anion u = {3, 4}; - eputs ("u.foo:"); eputs (itoa (u.foo)); eputs ("\n"); - eputs ("u.bla:"); eputs (itoa (u.bla)); eputs ("\n"); + struct anion u = { 3, 4 }; + eputs ("u.foo:"); + eputs (itoa (u.foo)); + eputs ("\n"); + eputs ("u.bla:"); + eputs (itoa (u.bla)); + eputs ("\n"); if (u.foo != 3) return 24; if (u.bla != 4) return 25; - struct nest n = {0}; + struct nest n = { 0 }; if (n.bar.baz) return 26; @@ -169,24 +205,25 @@ main (int argc, char* argv[]) char buf[sizeof (g_f.string)]; char buf1[sizeof (g_g->string)]; - int (*fun)(int, char **); + int (*fun) (int, char **); fun = &next_main; //i = (*fun)(argc, argv); - int (*fun2)(int, char *[]); + int (*fun2) (int, char *[]); fun2 = &next_main; //i = (*fun2)(argc, argv); i = 1; - int lst[6] = {-1, 1 - 1, i, 2, 3}; + int lst[6] = { -1, 1 - 1, i, 2, 3 }; for (int i = 0; i < 4; i++) { - eputs ("i: "); eputs (itoa (lst[i])); eputs ("\n"); - if (lst[i+1] != i) + eputs ("i: "); + eputs (itoa (lst[i])); + eputs ("\n"); + if (lst[i + 1] != i) return 30 + i; } - eputs ("foo" - "bar"); + eputs ("foo" "bar"); return 0; } diff --git a/scaffold/tiny-mes.c b/scaffold/tiny-mes.c index fe3ac018..0ab83381 100644 --- a/scaffold/tiny-mes.c +++ b/scaffold/tiny-mes.c @@ -33,14 +33,17 @@ char arena[300]; typedef int SCM; SCM g_stack = 0; -SCM r0 = 0; // a/env -SCM r1 = 0; // param 1 -SCM r2 = 0; // save 2+load/dump -SCM r3 = 0; // continuation +SCM r0 = 0; // a/env +SCM r1 = 0; // param 1 +SCM r2 = 0; // save 2+load/dump +SCM r3 = 0; // continuation -enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART}; +enum type_t +{ TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, + TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART }; -struct scm { +struct scm +{ enum type_t type; SCM car; SCM cdr; @@ -49,7 +52,7 @@ struct scm { #if __MESC__ struct scm *g_cells = arena; #else -struct scm *g_cells = (struct scm*)arena; +struct scm *g_cells = (struct scm *) arena; #endif #define cell_nil 1 @@ -75,10 +78,29 @@ cdr (SCM x) return CDR (x); } -SCM caar (SCM x) {return car (car (x));} -SCM cadr (SCM x) {return car (cdr (x));} -SCM cdar (SCM x) {return cdr (car (x));} -SCM cddr (SCM x) {return cdr (cdr (x));} +SCM +caar (SCM x) +{ + return car (car (x)); +} + +SCM +cadr (SCM x) +{ + return car (cdr (x)); +} + +SCM +cdar (SCM x) +{ + return cdr (car (x)); +} + +SCM +cddr (SCM x) +{ + return cdr (cdr (x)); +} SCM gc_peek_frame () @@ -195,7 +217,8 @@ display_ (SCM x) //puts ("\n"); //if (cont != cell_f) puts "("); puts ("("); - if (x && x != cell_nil) display_ (CAR (x)); + if (x && x != cell_nil) + display_ (CAR (x)); if (CDR (x) && CDR (x) != cell_nil) { #if __GNUC__ @@ -218,17 +241,29 @@ display_ (SCM x) { switch (x) { - case 1: {puts ("()"); break;} - case 2: {puts ("#f"); break;} - case 3: {puts ("#t"); break;} + case 1: + { + puts ("()"); + break; + } + case 2: + { + puts ("#f"); + break; + } + case 3: + { + puts ("#t"); + break; + } default: { #if __GNUC__ - puts (""); + puts (""); #else - puts (""); + puts (""); #endif } } @@ -238,24 +273,64 @@ display_ (SCM x) { switch (x) { - case 11: {puts (" . "); break;} - case 12: {puts ("lambda"); break;} - case 13: {puts ("begin"); break;} - case 14: {puts ("if"); break;} - case 15: {puts ("quote"); break;} - case 37: {puts ("car"); break;} - case 38: {puts ("cdr"); break;} - case 39: {puts ("null?"); break;} - case 40: {puts ("eq?"); break;} - case 41: {puts ("cons"); break;} + case 11: + { + puts (" . "); + break; + } + case 12: + { + puts ("lambda"); + break; + } + case 13: + { + puts ("begin"); + break; + } + case 14: + { + puts ("if"); + break; + } + case 15: + { + puts ("quote"); + break; + } + case 37: + { + puts ("car"); + break; + } + case 38: + { + puts ("cdr"); + break; + } + case 39: + { + puts ("null?"); + break; + } + case 40: + { + puts ("eq?"); + break; + } + case 41: + { + puts ("cons"); + break; + } default: { #if __GNUC__ - puts (""); + puts (""); #else - puts (""); + puts (""); #endif } } @@ -280,29 +355,36 @@ display_ (SCM x) } SCM -bload_env (SCM a) ///((internal)) +bload_env (SCM a) ///((internal)) { puts ("reading: "); char *mo = "module/mes/tiny-0-32.mo"; puts (mo); puts ("\n"); __stdin = open (mo, 0); - if (__stdin < 0) {eputs ("no such file: module/mes/tiny-0-32.mo\n");return 1;} + if (__stdin < 0) + { + eputs ("no such file: module/mes/tiny-0-32.mo\n"); + return 1; + } // BOOM //char *p = arena; - char *p = (char*)g_cells; + char *p = (char *) g_cells; int c; c = getchar (); putchar (c); - if (c != 'M') exit (10); + if (c != 'M') + exit (10); c = getchar (); putchar (c); - if (c != 'E') exit (11); + if (c != 'E') + exit (11); c = getchar (); putchar (c); - if (c != 'S') exit (12); + if (c != 'S') + exit (12); puts (" *GOT MES*\n"); // skip stack diff --git a/src/gc.c b/src/gc.c index 21e2675e..696bcf81 100644 --- a/src/gc.c +++ b/src/gc.c @@ -23,9 +23,9 @@ size_t bytes_cells (size_t length); SCM -gc_up_arena () ///((internal)) +gc_up_arena () ///((internal)) { - long old_arena_bytes = (ARENA_SIZE+JAM_SIZE)*sizeof (struct scm); + long old_arena_bytes = (ARENA_SIZE + JAM_SIZE) * sizeof (struct scm); if (ARENA_SIZE >> 1 < MAX_ARENA_SIZE >> 2) { ARENA_SIZE <<= 1; @@ -33,9 +33,9 @@ gc_up_arena () ///((internal)) GC_SAFETY <<= 1; } else - ARENA_SIZE = MAX_ARENA_SIZE -JAM_SIZE; - long arena_bytes = (ARENA_SIZE+JAM_SIZE)*sizeof (struct scm); - void *p = realloc (g_cells-1, arena_bytes+STACK_SIZE*sizeof (SCM)); + ARENA_SIZE = MAX_ARENA_SIZE - JAM_SIZE; + long arena_bytes = (ARENA_SIZE + JAM_SIZE) * sizeof (struct scm); + void *p = realloc (g_cells - 1, arena_bytes + STACK_SIZE * sizeof (SCM)); if (!p) { eputs ("realloc failed, g_free="); @@ -46,15 +46,15 @@ gc_up_arena () ///((internal)) assert (0); exit (1); } - g_cells = (struct scm*)p; - memcpy (p + arena_bytes, p + old_arena_bytes, STACK_SIZE*sizeof (SCM)); + g_cells = (struct scm *) p; + memcpy (p + arena_bytes, p + old_arena_bytes, STACK_SIZE * sizeof (SCM)); g_cells++; return 0; } void -gc_flip () ///((internal)) +gc_flip () ///((internal)) { if (g_debug > 2) { @@ -64,22 +64,21 @@ gc_flip () ///((internal)) } if (g_free > JAM_SIZE) JAM_SIZE = g_free + g_free / 2; - memcpy (g_cells-1, g_news-1, (g_free+2)*sizeof (struct scm)); + memcpy (g_cells - 1, g_news - 1, (g_free + 2) * sizeof (struct scm)); } SCM -gc_copy (SCM old) ///((internal)) +gc_copy (SCM old) ///((internal)) { if (TYPE (old) == TBROKEN_HEART) return g_cells[old].car; SCM new = g_free++; g_news[new] = g_cells[old]; - if (NTYPE (new) == TSTRUCT - || NTYPE (new) == TVECTOR) + if (NTYPE (new) == TSTRUCT || NTYPE (new) == TVECTOR) { NVECTOR (new) = g_free; - for (long i=0; i 4) { - eputs ("gc copy bytes: "); eputs (src); eputs ("\n"); - eputs (" length: "); eputs (itoa (LENGTH (old))); eputs ("\n"); - eputs (" nlength: "); eputs (itoa (NLENGTH (new))); eputs ("\n"); - eputs (" ==> "); eputs (dest); eputs ("\n"); + eputs ("gc copy bytes: "); + eputs (src); + eputs ("\n"); + eputs (" length: "); + eputs (itoa (LENGTH (old))); + eputs ("\n"); + eputs (" nlength: "); + eputs (itoa (NLENGTH (new))); + eputs ("\n"); + eputs (" ==> "); + eputs (dest); + eputs ("\n"); } } TYPE (old) = TBROKEN_HEART; @@ -103,49 +110,36 @@ gc_copy (SCM old) ///((internal)) } SCM -gc_relocate_car (SCM new, SCM car) ///((internal)) +gc_relocate_car (SCM new, SCM car) ///((internal)) { g_news[new].car = car; return cell_unspecified; } SCM -gc_relocate_cdr (SCM new, SCM cdr) ///((internal)) +gc_relocate_cdr (SCM new, SCM cdr) ///((internal)) { g_news[new].cdr = cdr; return cell_unspecified; } void -gc_loop (SCM scan) ///((internal)) +gc_loop (SCM scan) ///((internal)) { SCM car; SCM cdr; while (scan < g_free) { if (NTYPE (scan) == TBROKEN_HEART) - error (cell_symbol_system_error, cstring_to_symbol ("gc")); - if (NTYPE (scan) == TMACRO - || NTYPE (scan) == TPAIR - || NTYPE (scan) == TREF - || scan == 1 // null + error (cell_symbol_system_error, cstring_to_symbol ("gc")); + if (NTYPE (scan) == TMACRO || NTYPE (scan) == TPAIR || NTYPE (scan) == TREF || scan == 1 // null || NTYPE (scan) == TVARIABLE) { car = gc_copy (g_news[scan].car); gc_relocate_car (scan, car); } - if ((NTYPE (scan) == TCLOSURE - || NTYPE (scan) == TCONTINUATION - || NTYPE (scan) == TKEYWORD - || NTYPE (scan) == TMACRO - || NTYPE (scan) == TPAIR - || NTYPE (scan) == TPORT - || NTYPE (scan) == TSPECIAL - || NTYPE (scan) == TSTRING - || NTYPE (scan) == TSYMBOL - || scan == 1 // null - || NTYPE (scan) == TVALUES) - && g_news[scan].cdr) // allow for 0 terminated list of symbols + if ((NTYPE (scan) == TCLOSURE || NTYPE (scan) == TCONTINUATION || NTYPE (scan) == TKEYWORD || NTYPE (scan) == TMACRO || NTYPE (scan) == TPAIR || NTYPE (scan) == TPORT || NTYPE (scan) == TSPECIAL || NTYPE (scan) == TSTRING || NTYPE (scan) == TSYMBOL || scan == 1 // null + || NTYPE (scan) == TVALUES) && g_news[scan].cdr) // allow for 0 terminated list of symbols { cdr = gc_copy (g_news[scan].cdr); gc_relocate_cdr (scan, cdr); @@ -166,7 +160,7 @@ gc_check () } SCM -gc_init_news () ///((internal)) +gc_init_news () ///((internal)) { g_news = g_cells + g_free; NTYPE (0) = TVECTOR; @@ -179,7 +173,7 @@ gc_init_news () ///((internal)) } SCM -gc_ () ///((internal)) +gc_ () ///((internal)) { gc_init_news (); if (g_debug == 2) @@ -195,7 +189,7 @@ gc_ () ///((internal)) g_free = 1; #if __MESC__ - if (ARENA_SIZE < MAX_ARENA_SIZE && (long)g_news > 0) + if (ARENA_SIZE < MAX_ARENA_SIZE && (long) g_news > 0) #else if (ARENA_SIZE < MAX_ARENA_SIZE && g_news > 0) #endif @@ -205,9 +199,9 @@ gc_ () ///((internal)) if (g_debug > 2) { eputs (" up["); - eputs (itoa ((unsigned long)g_cells)); + eputs (itoa ((unsigned long) g_cells)); eputs (","); - eputs (itoa ((unsigned long)g_news)); + eputs (itoa ((unsigned long) g_news)); eputs (":"); eputs (itoa (ARENA_SIZE)); eputs (","); @@ -217,14 +211,14 @@ gc_ () ///((internal)) gc_up_arena (); } - for (long i=g_free; i= 32 && v <= 127) @@ -93,15 +102,15 @@ display_helper (SCM x, int cont, char* sep, int fd, int write_p) { if (!cont) fdputs ("(", fd); - if (CAR (x) == cell_circular - && CADR (x) != cell_closure) + if (CAR (x) == cell_circular && CADR (x) != cell_closure) { fdputs ("(*circ* . ", fd); int i = 0; x = CDR (x); while (x != cell_nil && i++ < 10) { - fdisplay_ (CAAR (x), fd, write_p); fdputs (" ", fd); + fdisplay_ (CAAR (x), fd, write_p); + fdputs (" ", fd); x = CDR (x); } fdputs (" ...)", fd); @@ -122,17 +131,13 @@ display_helper (SCM x, int cont, char* sep, int fd, int write_p) if (!cont) fdputs (")", fd); } - else if (t == TKEYWORD - || t == TPORT - || t == TSPECIAL - || t == TSTRING - || t == TSYMBOL) + else if (t == TKEYWORD || t == TPORT || t == TSPECIAL || t == TSTRING || t == TSYMBOL) { if (t == TPORT) { fdputs ("#', __stdout); } SCM -make_frame_type () ///((internal)) +make_frame_type () ///((internal)) { - SCM record_type = cell_symbol_record_type; // FIXME + SCM record_type = cell_symbol_record_type; // FIXME SCM fields = cell_nil; fields = cons (cell_symbol_procedure, fields); fields = cons (fields, cell_nil); @@ -302,8 +320,8 @@ SCM make_frame (SCM stack, long index) { SCM frame_type = make_frame_type (); - long array_index = (STACK_SIZE-(index*FRAME_SIZE)); - SCM procedure = g_stack_array[array_index+FRAME_PROCEDURE]; + long array_index = (STACK_SIZE - (index * FRAME_SIZE)); + SCM procedure = g_stack_array[array_index + FRAME_PROCEDURE]; if (!procedure) procedure = cell_f; SCM values = cell_nil; @@ -313,9 +331,9 @@ make_frame (SCM stack, long index) } SCM -make_stack_type () ///((internal)) +make_stack_type () ///((internal)) { - SCM record_type = cell_symbol_record_type; // FIXME + SCM record_type = cell_symbol_record_type; // FIXME SCM fields = cell_nil; fields = cons (cstring_to_symbol ("frames"), fields); fields = cons (fields, cell_nil); @@ -324,12 +342,12 @@ make_stack_type () ///((internal)) } SCM -make_stack (SCM stack) ///((arity . n)) +make_stack (SCM stack) ///((arity . n)) { SCM stack_type = make_stack_type (); - long size = (STACK_SIZE-g_stack) / FRAME_SIZE; + long size = (STACK_SIZE - g_stack) / FRAME_SIZE; SCM frames = make_vector__ (size); - for (long i=0; i void -assert_number (char const* name, SCM x) +assert_number (char const *name, SCM x) { if (TYPE (x) != TNUMBER) { @@ -31,7 +31,7 @@ assert_number (char const* name, SCM x) } SCM -greater_p (SCM x) ///((name . ">") (arity . n)) +greater_p (SCM x) ///((name . ">") (arity . n)) { if (x == cell_nil) return cell_t; @@ -50,7 +50,7 @@ greater_p (SCM x) ///((name . ">") (arity . n)) } SCM -less_p (SCM x) ///((name . "<") (arity . n)) +less_p (SCM x) ///((name . "<") (arity . n)) { if (x == cell_nil) return cell_t; @@ -69,7 +69,7 @@ less_p (SCM x) ///((name . "<") (arity . n)) } SCM -is_p (SCM x) ///((name . "=") (arity . n)) +is_p (SCM x) ///((name . "=") (arity . n)) { if (x == cell_nil) return cell_t; @@ -86,7 +86,7 @@ is_p (SCM x) ///((name . "=") (arity . n)) } SCM -minus (SCM x) ///((name . "-") (arity . n)) +minus (SCM x) ///((name . "-") (arity . n)) { assert_number ("minus", CAR (x)); long n = VALUE (CAR (x)); @@ -103,7 +103,7 @@ minus (SCM x) ///((name . "-") (arity . n)) } SCM -plus (SCM x) ///((name . "+") (arity . n)) +plus (SCM x) ///((name . "+") (arity . n)) { long n = 0; while (x != cell_nil) @@ -116,7 +116,7 @@ plus (SCM x) ///((name . "+") (arity . n)) } SCM -divide (SCM x) ///((name . "/") (arity . n)) +divide (SCM x) ///((name . "/") (arity . n)) { long n = 1; if (x != cell_nil) @@ -149,7 +149,7 @@ modulo (SCM a, SCM b) } SCM -multiply (SCM x) ///((name . "*") (arity . n)) +multiply (SCM x) ///((name . "*") (arity . n)) { long n = 1; while (x != cell_nil) @@ -162,7 +162,7 @@ multiply (SCM x) ///((name . "*") (arity . n)) } SCM -logand (SCM x) ///((arity . n)) +logand (SCM x) ///((arity . n)) { long n = 0; while (x != cell_nil) @@ -175,7 +175,7 @@ logand (SCM x) ///((arity . n)) } SCM -logior (SCM x) ///((arity . n)) +logior (SCM x) ///((arity . n)) { long n = 0; while (x != cell_nil) @@ -196,7 +196,7 @@ lognot (SCM x) } SCM -logxor (SCM x) ///((arity . n)) +logxor (SCM x) ///((arity . n)) { long n = 0; while (x != cell_nil) diff --git a/src/mes.c b/src/mes.c index 9c37b784..b54bd4a6 100644 --- a/src/mes.c +++ b/src/mes.c @@ -28,9 +28,9 @@ //#define MES_MINI 1 #if WITH_GLIBC -long ARENA_SIZE = 100000000; // 2.3GiB +long ARENA_SIZE = 100000000; // 2.3GiB #else -long ARENA_SIZE = 300000; // 32b: 3MiB, 64b: 6 MiB +long ARENA_SIZE = 300000; // 32b: 3MiB, 64b: 6 MiB #endif long MAX_ARENA_SIZE = 100000000; long STACK_SIZE = 20000; @@ -444,9 +444,9 @@ struct scm *g_news = 0; #define CDADAR(x) CAR (CDR (CAR (CDR (x)))) SCM apply_builtin (SCM fn, SCM x); -SCM cstring_to_list (char const* s); +SCM cstring_to_list (char const *s); SCM cstring_to_symbol (char const *s); -SCM make_bytes (char const* s, size_t length); +SCM make_bytes (char const *s, size_t length); SCM make_hash_table_ (long size); SCM read_input_file_env (SCM); SCM string_equal_p (SCM a, SCM b); @@ -482,10 +482,9 @@ make_cell_ (SCM type, SCM car, SCM cdr) } SCM -assoc_string (SCM x, SCM a) ///((internal)) +assoc_string (SCM x, SCM a) ///((internal)) { - while (a != cell_nil && (TYPE (CAAR (a)) != TSTRING - || string_equal_p (x, CAAR (a)) == cell_f)) + while (a != cell_nil && (TYPE (CAAR (a)) != TSTRING || string_equal_p (x, CAAR (a)) == cell_f)) a = CDR (a); return a != cell_nil ? CAR (a) : cell_f; } @@ -523,12 +522,11 @@ type_ (SCM x) SCM car_ (SCM x) { - return (TYPE (x) != TCONTINUATION - && (TYPE (CAR (x)) == TPAIR // FIXME: this is weird - || TYPE (CAR (x)) == TREF - || TYPE (CAR (x)) == TSPECIAL - || TYPE (CAR (x)) == TSYMBOL - || TYPE (CAR (x)) == TSTRING)) ? CAR (x) : MAKE_NUMBER (CAR (x)); + return (TYPE (x) != TCONTINUATION && (TYPE (CAR (x)) == TPAIR // FIXME: this is weird + || TYPE (CAR (x)) == TREF + || TYPE (CAR (x)) == TSPECIAL + || TYPE (CAR (x)) == TSYMBOL + || TYPE (CAR (x)) == TSTRING)) ? CAR (x) : MAKE_NUMBER (CAR (x)); } SCM @@ -540,8 +538,7 @@ cdr_ (SCM x) && (TYPE (CDR (x)) == TPAIR || TYPE (CDR (x)) == TREF || TYPE (CDR (x)) == TSPECIAL - || TYPE (CDR (x)) == TSYMBOL - || TYPE (CDR (x)) == TSTRING)) ? CDR (x) : MAKE_NUMBER (CDR (x)); + || TYPE (CDR (x)) == TSYMBOL || TYPE (CDR (x)) == TSTRING)) ? CDR (x) : MAKE_NUMBER (CDR (x)); } SCM @@ -571,7 +568,7 @@ cdr (SCM x) } SCM -list (SCM x) ///((arity . n)) +list (SCM x) ///((arity . n)) { return x; } @@ -590,13 +587,11 @@ eq_p (SCM x, SCM y) && string_equal_p (x, y) == cell_t)) || (TYPE (x) == TCHAR && TYPE (y) == TCHAR && VALUE (x) == VALUE (y)) - || (TYPE (x) == TNUMBER && TYPE (y) == TNUMBER - && VALUE (x) == VALUE (y))) - ? cell_t : cell_f; + || (TYPE (x) == TNUMBER && TYPE (y) == TNUMBER && VALUE (x) == VALUE (y))) ? cell_t : cell_f; } SCM -values (SCM x) ///((arity . n)) +values (SCM x) ///((arity . n)) { SCM v = cons (0, x); TYPE (v) = TVALUES; @@ -610,7 +605,7 @@ acons (SCM key, SCM value, SCM alist) } long -length__ (SCM x) ///((internal)) +length__ (SCM x) ///((internal)) { long n = 0; while (x != cell_nil) @@ -649,17 +644,17 @@ error (SCM key, SCM x) // extra lib SCM -assert_defined (SCM x, SCM e) ///((internal)) +assert_defined (SCM x, SCM e) ///((internal)) { if (e == cell_undefined) return error (cell_symbol_unbound_variable, x); return e; } -SCM make_string (char const* s, size_t length); +SCM make_string (char const *s, size_t length); SCM -check_formals (SCM f, SCM formals, SCM args) ///((internal)) +check_formals (SCM f, SCM formals, SCM args) ///((internal)) { long flen = (TYPE (formals) == TNUMBER) ? VALUE (formals) : length__ (formals); long alen = length__ (args); @@ -679,9 +674,9 @@ check_formals (SCM f, SCM formals, SCM args) ///((internal)) } SCM -check_apply (SCM f, SCM e) ///((internal)) +check_apply (SCM f, SCM e) ///((internal)) { - char* type = 0; + char *type = 0; if (f == cell_f || f == cell_t) type = "bool"; if (f == cell_nil) @@ -696,8 +691,7 @@ check_apply (SCM f, SCM e) ///((internal)) type = "number"; if (TYPE (f) == TSTRING) type = "string"; - if (TYPE (f) == TSTRUCT - && builtin_p (f) == cell_f) + if (TYPE (f) == TSTRUCT && builtin_p (f) == cell_f) type = "#<...>"; if (TYPE (f) == TBROKEN_HEART) type = "<3"; @@ -717,7 +711,7 @@ check_apply (SCM f, SCM e) ///((internal)) } SCM -gc_push_frame () ///((internal)) +gc_push_frame () ///((internal)) { if (g_stack < 5) assert (!"STACK FULL"); @@ -730,17 +724,17 @@ gc_push_frame () ///((internal)) } SCM -gc_peek_frame () ///((internal)) +gc_peek_frame () ///((internal)) { r3 = g_stack_array[g_stack]; - r2 = g_stack_array[g_stack+1]; - r1 = g_stack_array[g_stack+2]; - r0 = g_stack_array[g_stack+3]; - return g_stack_array[g_stack+FRAME_PROCEDURE]; + r2 = g_stack_array[g_stack + 1]; + r1 = g_stack_array[g_stack + 2]; + r0 = g_stack_array[g_stack + 3]; + return g_stack_array[g_stack + FRAME_PROCEDURE]; } SCM -gc_pop_frame () ///((internal)) +gc_pop_frame () ///((internal)) { SCM x = gc_peek_frame (); g_stack += 5; @@ -801,8 +795,7 @@ pairlis (SCM x, SCM y, SCM a) return a; if (TYPE (x) != TPAIR) return cons (cons (x, y), a); - return cons (cons (car (x), car (y)), - pairlis (cdr (x), cdr (y), a)); + return cons (cons (car (x), car (y)), pairlis (cdr (x), cdr (y), a)); } SCM @@ -811,17 +804,15 @@ assq (SCM x, SCM a) if (TYPE (a) != TPAIR) return cell_f; int t = TYPE (x); - if (t == TSYMBOL - || t == TSPECIAL) + if (t == TSYMBOL || t == TSPECIAL) while (a != cell_nil && x != CAAR (a)) a = CDR (a); - else if (t == TCHAR - || t == TNUMBER) - { - SCM v = VALUE (x); - while (a != cell_nil && v != VALUE (CAAR (a))) - a = CDR (a); - } + else if (t == TCHAR || t == TNUMBER) + { + SCM v = VALUE (x); + while (a != cell_nil && v != VALUE (CAAR (a))) + a = CDR (a); + } else if (t == TKEYWORD) { while (a != cell_nil && string_equal_p (x, CAAR (a)) == cell_f) @@ -876,7 +867,7 @@ set_env_x (SCM x, SCM e, SCM a) } SCM -call_lambda (SCM e, SCM x, SCM aa, SCM a) ///((internal)) +call_lambda (SCM e, SCM x, SCM aa, SCM a) ///((internal)) { SCM cl = cons (cons (cell_closure, x), x); r1 = e; @@ -885,13 +876,13 @@ call_lambda (SCM e, SCM x, SCM aa, SCM a) ///((internal)) } SCM -make_closure_ (SCM args, SCM body, SCM a) ///((internal)) +make_closure_ (SCM args, SCM body, SCM a) ///((internal)) { return make_cell__ (TCLOSURE, cell_f, cons (cons (cell_circular, a), cons (args, body))); } SCM -make_variable_ (SCM var) ///((internal)) +make_variable_ (SCM var) ///((internal)) { return make_cell__ (TVARIABLE, var, 0); } @@ -905,7 +896,7 @@ macro_get_handle (SCM name) } SCM -get_macro (SCM name) ///((internal)) +get_macro (SCM name) ///((internal)) { SCM m = macro_get_handle (name); if (m != cell_f) @@ -914,13 +905,13 @@ get_macro (SCM name) ///((internal)) } SCM -macro_set_x (SCM name, SCM value) ///((internal)) +macro_set_x (SCM name, SCM value) ///((internal)) { return hashq_set_x (g_macros, name, value); } SCM -push_cc (SCM p1, SCM p2, SCM a, SCM c) ///((internal)) +push_cc (SCM p1, SCM p2, SCM a, SCM c) ///((internal)) { SCM x = r3; r3 = c; @@ -946,13 +937,14 @@ add_formals (SCM formals, SCM x) } int -formal_p (SCM x, SCM formals) /// ((internal)) +formal_p (SCM x, SCM formals) /// ((internal)) { if (TYPE (formals) == TSYMBOL) { if (x == formals) return x; - else return cell_f; + else + return cell_f; } while (TYPE (formals) == TPAIR && CAR (formals) != x) formals = CDR (formals); @@ -962,7 +954,7 @@ formal_p (SCM x, SCM formals) /// ((internal)) } SCM -expand_variable_ (SCM x, SCM formals, int top_p) ///((internal)) +expand_variable_ (SCM x, SCM formals, int top_p) ///((internal)) { while (TYPE (x) == TPAIR) { @@ -973,8 +965,7 @@ expand_variable_ (SCM x, SCM formals, int top_p) ///((internal)) SCM f = CAR (CDAR (x)); formals = add_formals (formals, f); } - else if (CAAR (x) == cell_symbol_define - || CAAR (x) == cell_symbol_define_macro) + else if (CAAR (x) == cell_symbol_define || CAAR (x) == cell_symbol_define_macro) { SCM f = CAR (CDAR (x)); formals = add_formals (formals, f); @@ -990,8 +981,7 @@ expand_variable_ (SCM x, SCM formals, int top_p) ///((internal)) formals = add_formals (formals, f); x = CDR (x); } - else if (CAR (x) == cell_symbol_define - || CAR (x) == cell_symbol_define_macro) + else if (CAR (x) == cell_symbol_define || CAR (x) == cell_symbol_define_macro) { SCM f = CADR (x); if (top_p && TYPE (f) == TPAIR) @@ -1004,8 +994,7 @@ expand_variable_ (SCM x, SCM formals, int top_p) ///((internal)) else if (TYPE (CAR (x)) == TSYMBOL && CAR (x) != cell_symbol_boot_module && CAR (x) != cell_symbol_current_module - && CAR (x) != cell_symbol_primitive_load - && !formal_p (CAR (x), formals)) + && CAR (x) != cell_symbol_primitive_load && !formal_p (CAR (x), formals)) { SCM v = module_variable (r0, CAR (x)); if (v != cell_f) @@ -1019,7 +1008,7 @@ expand_variable_ (SCM x, SCM formals, int top_p) ///((internal)) } SCM -expand_variable (SCM x, SCM formals) ///((internal)) +expand_variable (SCM x, SCM formals) ///((internal)) { return expand_variable_ (x, formals, 1); } @@ -1052,67 +1041,100 @@ eval_apply () int t; long c; - eval_apply: - if (r3 == cell_vm_evlis2) goto evlis2; - else if (r3 == cell_vm_evlis3) goto evlis3; - else if (r3 == cell_vm_eval_check_func) goto eval_check_func; - else if (r3 == cell_vm_eval2) goto eval2; - else if (r3 == cell_vm_apply2) goto apply2; - else if (r3 == cell_vm_if_expr) goto if_expr; - else if (r3 == cell_vm_begin_eval) goto begin_eval; - else if (r3 == cell_vm_eval_set_x) goto eval_set_x; - else if (r3 == cell_vm_macro_expand_car) goto macro_expand_car; - else if (r3 == cell_vm_return) goto vm_return; - else if (r3 == cell_vm_macro_expand_cdr) goto macro_expand_cdr; - else if (r3 == cell_vm_eval_define) goto eval_define; - else if (r3 == cell_vm_macro_expand) goto macro_expand; - else if (r3 == cell_vm_macro_expand_lambda) goto macro_expand_lambda; - else if (r3 == cell_vm_eval_pmatch_car) goto eval_pmatch_car; - else if (r3 == cell_vm_begin_expand_macro) goto begin_expand_macro; - else if (r3 == cell_vm_macro_expand_define) goto macro_expand_define; - else if (r3 == cell_vm_begin_expand_eval) goto begin_expand_eval; - else if (r3 == cell_vm_call_with_current_continuation2) goto call_with_current_continuation2; - else if (r3 == cell_vm_macro_expand_set_x) goto macro_expand_set_x; - else if (r3 == cell_vm_eval_pmatch_cdr) goto eval_pmatch_cdr; - else if (r3 == cell_vm_macro_expand_define_macro) goto macro_expand_define_macro; - else if (r3 == cell_vm_begin_primitive_load) goto begin_primitive_load; +eval_apply: + if (r3 == cell_vm_evlis2) + goto evlis2; + else if (r3 == cell_vm_evlis3) + goto evlis3; + else if (r3 == cell_vm_eval_check_func) + goto eval_check_func; + else if (r3 == cell_vm_eval2) + goto eval2; + else if (r3 == cell_vm_apply2) + goto apply2; + else if (r3 == cell_vm_if_expr) + goto if_expr; + else if (r3 == cell_vm_begin_eval) + goto begin_eval; + else if (r3 == cell_vm_eval_set_x) + goto eval_set_x; + else if (r3 == cell_vm_macro_expand_car) + goto macro_expand_car; + else if (r3 == cell_vm_return) + goto vm_return; + else if (r3 == cell_vm_macro_expand_cdr) + goto macro_expand_cdr; + else if (r3 == cell_vm_eval_define) + goto eval_define; + else if (r3 == cell_vm_macro_expand) + goto macro_expand; + else if (r3 == cell_vm_macro_expand_lambda) + goto macro_expand_lambda; + else if (r3 == cell_vm_eval_pmatch_car) + goto eval_pmatch_car; + else if (r3 == cell_vm_begin_expand_macro) + goto begin_expand_macro; + else if (r3 == cell_vm_macro_expand_define) + goto macro_expand_define; + else if (r3 == cell_vm_begin_expand_eval) + goto begin_expand_eval; + else if (r3 == cell_vm_call_with_current_continuation2) + goto call_with_current_continuation2; + else if (r3 == cell_vm_macro_expand_set_x) + goto macro_expand_set_x; + else if (r3 == cell_vm_eval_pmatch_cdr) + goto eval_pmatch_cdr; + else if (r3 == cell_vm_macro_expand_define_macro) + goto macro_expand_define_macro; + else if (r3 == cell_vm_begin_primitive_load) + goto begin_primitive_load; - else if (r3 == cell_vm_evlis) goto evlis; - else if (r3 == cell_vm_apply) goto apply; - else if (r3 == cell_vm_eval) goto eval; - else if (r3 == cell_vm_eval_macro_expand_eval) goto eval_macro_expand_eval; - else if (r3 == cell_vm_eval_macro_expand_expand) goto eval_macro_expand_expand; - else if (r3 == cell_vm_begin) goto begin; - else if (r3 == cell_vm_begin_expand) goto begin_expand; - else if (r3 == cell_vm_begin_expand_primitive_load) goto begin_expand_primitive_load; - else if (r3 == cell_vm_if) goto vm_if; - else if (r3 == cell_vm_call_with_values2) goto call_with_values2; - else if (r3 == cell_unspecified) return r1; + else if (r3 == cell_vm_evlis) + goto evlis; + else if (r3 == cell_vm_apply) + goto apply; + else if (r3 == cell_vm_eval) + goto eval; + else if (r3 == cell_vm_eval_macro_expand_eval) + goto eval_macro_expand_eval; + else if (r3 == cell_vm_eval_macro_expand_expand) + goto eval_macro_expand_expand; + else if (r3 == cell_vm_begin) + goto begin; + else if (r3 == cell_vm_begin_expand) + goto begin_expand; + else if (r3 == cell_vm_begin_expand_primitive_load) + goto begin_expand_primitive_load; + else if (r3 == cell_vm_if) + goto vm_if; + else if (r3 == cell_vm_call_with_values2) + goto call_with_values2; + else if (r3 == cell_unspecified) + return r1; else - error (cell_symbol_system_error, - MAKE_STRING0 ("eval/apply unknown continuation")); + error (cell_symbol_system_error, MAKE_STRING0 ("eval/apply unknown continuation")); - evlis: +evlis: if (r1 == cell_nil) goto vm_return; if (TYPE (r1) != TPAIR) goto eval; push_cc (CAR (r1), r1, r0, cell_vm_evlis2); goto eval; - evlis2: +evlis2: push_cc (CDR (r2), r1, r0, cell_vm_evlis3); goto evlis; - evlis3: +evlis3: r1 = cons (r2, r1); goto vm_return; - apply: - g_stack_array[g_stack+FRAME_PROCEDURE] = CAR (r1); +apply: + g_stack_array[g_stack + FRAME_PROCEDURE] = CAR (r1); t = TYPE (CAR (r1)); if (t == TSTRUCT && builtin_p (CAR (r1)) == cell_t) { check_formals (CAR (r1), builtin_arity (CAR (r1)), CDR (r1)); - r1 = apply_builtin (CAR (r1), CDR (r1)); /// FIXME: move into eval_apply + r1 = apply_builtin (CAR (r1), CDR (r1)); /// FIXME: move into eval_apply goto vm_return; } else if (t == TCLOSURE) @@ -1133,9 +1155,9 @@ eval_apply () v = CONTINUATION (CAR (r1)); if (LENGTH (v)) { - for (t=0; t < LENGTH (v); t++) - g_stack_array[STACK_SIZE-LENGTH (v)+t] = vector_ref_ (v, t); - g_stack = STACK_SIZE-LENGTH (v); + for (t = 0; t < LENGTH (v); t++) + g_stack_array[STACK_SIZE - LENGTH (v) + t] = vector_ref_ (v, t); + g_stack = STACK_SIZE - LENGTH (v); } x = r1; gc_pop_frame (); @@ -1150,17 +1172,17 @@ eval_apply () push_cc (cons (CADR (r1), CADDR (r1)), r1, r0, cell_vm_return); goto apply; } - else if (c == cell_vm_eval) + else if (c == cell_vm_eval) { push_cc (CADR (r1), r1, CADDR (r1), cell_vm_return); goto eval; } - else if (c == cell_vm_begin_expand) + else if (c == cell_vm_begin_expand) { push_cc (cons (CADR (r1), cell_nil), r1, CADDR (r1), cell_vm_return); goto begin_expand; } - else if (c == cell_call_with_current_continuation) + else if (c == cell_call_with_current_continuation) { r1 = CDR (r1); goto call_with_current_continuation; @@ -1203,17 +1225,17 @@ eval_apply () // eputs ("\n"); push_cc (CAR (r1), r1, r0, cell_vm_apply2); goto eval; - apply2: +apply2: check_apply (r1, CAR (r2)); r1 = cons (r1, CDR (r2)); goto apply; - eval: +eval: t = TYPE (r1); if (t == TPAIR) { c = CAR (r1); - if (c == cell_symbol_pmatch_car) + if (c == cell_symbol_pmatch_car) { push_cc (CADR (r1), r1, r0, cell_vm_eval_pmatch_car); goto eval; @@ -1223,7 +1245,7 @@ eval_apply () r1 = CAR (x); goto eval_apply; } - else if (c == cell_symbol_pmatch_cdr) + else if (c == cell_symbol_pmatch_cdr) { push_cc (CADR (r1), r1, r0, cell_vm_eval_pmatch_cdr); goto eval; @@ -1233,26 +1255,26 @@ eval_apply () r1 = CDR (x); goto eval_apply; } - else if (c == cell_symbol_quote) + else if (c == cell_symbol_quote) { x = r1; gc_pop_frame (); r1 = CADR (x); goto eval_apply; } - else if (c == cell_symbol_begin) + else if (c == cell_symbol_begin) goto begin; - else if (c == cell_symbol_lambda) + else if (c == cell_symbol_lambda) { r1 = make_closure_ (CADR (r1), CDDR (r1), r0); goto vm_return; } - else if (c == cell_symbol_if) + else if (c == cell_symbol_if) { - r1=CDR (r1); + r1 = CDR (r1); goto vm_if; } - else if (c == cell_symbol_set_x) + else if (c == cell_symbol_set_x) { push_cc (CAR (CDDR (r1)), r1, r0, cell_vm_eval_set_x); goto eval; @@ -1272,9 +1294,7 @@ eval_apply () } else { - if (TYPE (r1) == TPAIR - && (CAR (r1) == cell_symbol_define - || CAR (r1) == cell_symbol_define_macro)) + if (TYPE (r1) == TPAIR && (CAR (r1) == cell_symbol_define || CAR (r1) == cell_symbol_define_macro)) { global_p = CAAR (r0) != cell_closure; macro_p = CAR (r1) == cell_symbol_define_macro; @@ -1358,7 +1378,7 @@ eval_apply () goto vm_return; if (r1 == cell_symbol_current_module) goto vm_return; - if (r1 == cell_symbol_begin) // FIXME + if (r1 == cell_symbol_begin) // FIXME { r1 = cell_begin; goto vm_return; @@ -1372,11 +1392,11 @@ eval_apply () goto vm_return; } else if (t == TBROKEN_HEART) - error (cell_symbol_system_error, r1); + error (cell_symbol_system_error, r1); else goto vm_return; - macro_expand: +macro_expand: { macro; expanders; @@ -1394,16 +1414,14 @@ eval_apply () goto vm_return; } - if (TYPE (r1) == TPAIR - && (macro = get_macro (CAR (r1))) != cell_f) + if (TYPE (r1) == TPAIR && (macro = get_macro (CAR (r1))) != cell_f) { r1 = cons (macro, CDR (r1)); push_cc (r1, cell_nil, r0, cell_vm_macro_expand); goto apply; } - if (CAR (r1) == cell_symbol_define - || CAR (r1) == cell_symbol_define_macro) + if (CAR (r1) == cell_symbol_define || CAR (r1) == cell_symbol_define_macro) { push_cc (CDDR (r1), r1, r0, cell_vm_macro_expand_define); goto macro_expand; @@ -1465,7 +1483,7 @@ eval_apply () goto vm_return; } - begin: +begin: x = cell_unspecified; while (r1 != cell_nil) { @@ -1503,7 +1521,7 @@ eval_apply () goto vm_return; - begin_expand: +begin_expand: x = cell_unspecified; while (r1 != cell_nil) { @@ -1516,7 +1534,7 @@ eval_apply () if (CAAR (r1) == cell_symbol_primitive_load) { push_cc (CADR (CAR (r1)), r1, r0, cell_vm_begin_expand_primitive_load); - goto eval; // FIXME: expand too?! + goto eval; // FIXME: expand too?! begin_expand_primitive_load: if (TYPE (r1) == TNUMBER && VALUE (r1) == 0) ; @@ -1562,10 +1580,10 @@ eval_apply () r1 = x; goto vm_return; - vm_if: +vm_if: push_cc (CAR (r1), r1, r0, cell_vm_if_expr); goto eval; - if_expr: +if_expr: x = r1; r1 = r2; if (x != cell_f) @@ -1581,33 +1599,33 @@ eval_apply () r1 = cell_unspecified; goto vm_return; - call_with_current_continuation: +call_with_current_continuation: gc_push_frame (); x = MAKE_CONTINUATION (g_continuations++); - v = make_vector__ (STACK_SIZE-g_stack); - for (t=g_stack; t < STACK_SIZE; t++) - vector_set_x_ (v, t-g_stack, g_stack_array[t]); + v = make_vector__ (STACK_SIZE - g_stack); + for (t = g_stack; t < STACK_SIZE; t++) + vector_set_x_ (v, t - g_stack, g_stack_array[t]); CONTINUATION (x) = v; gc_pop_frame (); push_cc (cons (CAR (r1), cons (x, cell_nil)), x, r0, cell_vm_call_with_current_continuation2); goto apply; - call_with_current_continuation2: - v = make_vector__ (STACK_SIZE-g_stack); - for (t=g_stack; t < STACK_SIZE; t++) - vector_set_x_ (v, t-g_stack, g_stack_array[t]); +call_with_current_continuation2: + v = make_vector__ (STACK_SIZE - g_stack); + for (t = g_stack; t < STACK_SIZE; t++) + vector_set_x_ (v, t - g_stack, g_stack_array[t]); CONTINUATION (r2) = v; goto vm_return; - call_with_values: +call_with_values: push_cc (cons (CAR (r1), cell_nil), r1, r0, cell_vm_call_with_values2); goto apply; - call_with_values2: +call_with_values2: if (TYPE (r1) == TVALUES) r1 = CDR (r1); r1 = cons (CADR (r2), r1); goto apply; - vm_return: +vm_return: x = r1; gc_pop_frame (); r1 = x; @@ -1615,7 +1633,7 @@ eval_apply () } SCM -apply (SCM f, SCM x, SCM a) ///((internal)) +apply (SCM f, SCM x, SCM a) ///((internal)) { push_cc (cons (f, x), cell_unspecified, r0, cell_unspecified); r3 = cell_vm_apply; @@ -1623,7 +1641,7 @@ apply (SCM f, SCM x, SCM a) ///((internal)) } SCM -mes_g_stack (SCM a) ///((internal)) +mes_g_stack (SCM a) ///((internal)) { //g_stack = g_free + ARENA_SIZE; g_stack = STACK_SIZE; @@ -1638,12 +1656,12 @@ mes_g_stack (SCM a) ///((internal)) SCM g_symbol_max; SCM -gc_init_cells () ///((internal)) +gc_init_cells () ///((internal)) { - long arena_bytes = (ARENA_SIZE+JAM_SIZE)*sizeof (struct scm); - void *p = malloc (arena_bytes+STACK_SIZE*sizeof (SCM)); - g_cells = (struct scm *)p; - g_stack_array = (SCM*)(p + arena_bytes); + long arena_bytes = (ARENA_SIZE + JAM_SIZE) * sizeof (struct scm); + void *p = malloc (arena_bytes + STACK_SIZE * sizeof (SCM)); + g_cells = (struct scm *) p; + g_stack_array = (SCM *) (p + arena_bytes); TYPE (0) = TVECTOR; LENGTH (0) = 1000; @@ -1653,13 +1671,13 @@ gc_init_cells () ///((internal)) VALUE (0) = 'c'; // FIXME: remove MES_MAX_STRING, grow dynamically - g_buf = (char*)malloc (MAX_STRING); + g_buf = (char *) malloc (MAX_STRING); return 0; } void -init_symbol (long x, long type, char const* name) +init_symbol (long x, long type, char const *name) { TYPE (x) = type; int length = strlen (name); @@ -1670,7 +1688,7 @@ init_symbol (long x, long type, char const* name) } SCM -mes_symbols () ///((internal)) +mes_symbols () ///((internal)) { gc_init_cells (); @@ -1864,7 +1882,7 @@ mes_environment (int argc, char *argv[]) #if !MES_MINI SCM lst = cell_nil; - for (int i=argc-1; i>=0; i--) + for (int i = argc - 1; i >= 0; i--) lst = cons (MAKE_STRING0 (argv[i]), lst); a = acons (cell_symbol_argv, lst, a); #endif @@ -1873,14 +1891,16 @@ mes_environment (int argc, char *argv[]) } SCM -init_builtin (SCM builtin_type, char const* name, int arity, SCM (*function) (SCM), SCM a) +init_builtin (SCM builtin_type, char const *name, int arity, SCM (*function) (SCM), SCM a) { SCM s = cstring_to_symbol (name); - return acons (s, make_builtin (builtin_type, symbol_to_string (s), MAKE_NUMBER (arity), MAKE_NUMBER (function)), a); + return acons (s, + make_builtin (builtin_type, symbol_to_string (s), MAKE_NUMBER (arity), + MAKE_NUMBER (function)), a); } SCM -make_builtin_type () ///(internal)) +make_builtin_type () ///(internal)) { SCM record_type = cell_symbol_record_type; SCM fields = cell_nil; @@ -1922,18 +1942,16 @@ builtin_function (SCM builtin) return VALUE (struct_ref_ (builtin, 5)); } #else -SCM -(*builtin_function (SCM builtin)) (SCM) +SCM (*builtin_function (SCM builtin)) (SCM) { - return (function1_t)VALUE (struct_ref_ (builtin, 5)); + return (function1_t) VALUE (struct_ref_ (builtin, 5)); } #endif SCM builtin_p (SCM x) { - return (TYPE (x) == TSTRUCT && struct_ref_ (x, 2) == cell_symbol_builtin) - ? cell_t : cell_f; + return (TYPE (x) == TSTRUCT && struct_ref_ (x, 2) == cell_symbol_builtin) ? cell_t : cell_f; } SCM @@ -1959,19 +1977,16 @@ builtin_printer (SCM builtin) } SCM -apply_builtin (SCM fn, SCM x) ///((internal)) +apply_builtin (SCM fn, SCM x) ///((internal)) { int arity = VALUE (builtin_arity (fn)); - if ((arity > 0 || arity == -1) - && x != cell_nil && TYPE (CAR (x)) == TVALUES) + if ((arity > 0 || arity == -1) && x != cell_nil && TYPE (CAR (x)) == TVALUES) x = cons (CADAR (x), CDR (x)); - if ((arity > 1 || arity == -1) - && x != cell_nil && TYPE (CDR (x)) == TPAIR && TYPE (CADR (x)) == TVALUES) + if ((arity > 1 || arity == -1) && x != cell_nil && TYPE (CDR (x)) == TPAIR && TYPE (CADR (x)) == TVALUES) x = cons (CAR (x), cons (CDADAR (x), CDR (x))); #if __M2_PLANET__ - FUNCTION fp = builtin_function (fn) - if (arity == 0) + FUNCTION fp = builtin_function (fn) if (arity == 0) return fp (); else if (arity == 1) return fp (CAR (x)); @@ -1985,31 +2000,31 @@ apply_builtin (SCM fn, SCM x) ///((internal)) if (arity == 0) { //function0_t fp = f->function; - SCM (*fp) (void) = (function0_t)builtin_function (fn); + SCM (*fp) (void) = (function0_t) builtin_function (fn); return fp (); } else if (arity == 1) { //function1_t fp = f->function; - SCM (*fp) (SCM) = (function1_t)builtin_function (fn); + SCM (*fp) (SCM) = (function1_t) builtin_function (fn); return fp (CAR (x)); } else if (arity == 2) { //function2_t fp = f->function; - SCM (*fp) (SCM, SCM) = (function2_t)builtin_function (fn); + SCM (*fp) (SCM, SCM) = (function2_t) builtin_function (fn); return fp (CAR (x), CADR (x)); } else if (arity == 3) { //function3_t fp = f->function; - SCM (*fp) (SCM, SCM, SCM) = (function3_t)builtin_function (fn); + SCM (*fp) (SCM, SCM, SCM) = (function3_t) builtin_function (fn); return fp (CAR (x), CADR (x), CAR (CDDR (x))); } else if (arity == -1) { //functionn_t fp = f->function; - SCM (*fp) (SCM) = (function1_t)builtin_function (fn); + SCM (*fp) (SCM) = (function1_t) builtin_function (fn); return fp (x); } #endif //! __M2_PLANET__ @@ -2017,7 +2032,7 @@ apply_builtin (SCM fn, SCM x) ///((internal)) } SCM -mes_builtins (SCM a) ///((internal)) +mes_builtins (SCM a) ///((internal)) { // TODO minimal: cons, car, cdr, list, null_p, eq_p minus, plus // display_, display_error_, getenv @@ -2025,157 +2040,157 @@ mes_builtins (SCM a) ///((internal)) SCM builtin_type = make_builtin_type (); // src/gc.mes - a = init_builtin (builtin_type, "gc-check", 0, (function1_t)&gc_check, a); - a = init_builtin (builtin_type, "gc", 0, (function1_t)&gc, a); + a = init_builtin (builtin_type, "gc-check", 0, (function1_t) & gc_check, a); + a = init_builtin (builtin_type, "gc", 0, (function1_t) & gc, a); // src/hash.mes - a = init_builtin (builtin_type, "hashq", 2, (function1_t)&hashq, a); - a = init_builtin (builtin_type, "hash", 2, (function1_t)&hash, a); - a = init_builtin (builtin_type, "hashq-get-handle", 3, (function1_t)&hashq_get_handle, a); - a = init_builtin (builtin_type, "hashq-ref", 3, (function1_t)&hashq_ref, a); - a = init_builtin (builtin_type, "hash-ref", 3, (function1_t)&hash_ref, a); - a = init_builtin (builtin_type, "hashq-set!", 3, (function1_t)&hashq_set_x, a); - a = init_builtin (builtin_type, "hash-set!", 3, (function1_t)&hash_set_x, a); - a = init_builtin (builtin_type, "hash-table-printer", 1, (function1_t)&hash_table_printer, a); - a = init_builtin (builtin_type, "make-hash-table", 1, (function1_t)&make_hash_table, a); + a = init_builtin (builtin_type, "hashq", 2, (function1_t) & hashq, a); + a = init_builtin (builtin_type, "hash", 2, (function1_t) & hash, a); + a = init_builtin (builtin_type, "hashq-get-handle", 3, (function1_t) & hashq_get_handle, a); + a = init_builtin (builtin_type, "hashq-ref", 3, (function1_t) & hashq_ref, a); + a = init_builtin (builtin_type, "hash-ref", 3, (function1_t) & hash_ref, a); + a = init_builtin (builtin_type, "hashq-set!", 3, (function1_t) & hashq_set_x, a); + a = init_builtin (builtin_type, "hash-set!", 3, (function1_t) & hash_set_x, a); + a = init_builtin (builtin_type, "hash-table-printer", 1, (function1_t) & hash_table_printer, a); + a = init_builtin (builtin_type, "make-hash-table", 1, (function1_t) & make_hash_table, a); // src/lib.mes - a = init_builtin (builtin_type, "core:display", 1, (function1_t)&display_, a); - a = init_builtin (builtin_type, "core:display-error", 1, (function1_t)&display_error_, a); - a = init_builtin (builtin_type, "core:display-port", 2, (function1_t)&display_port_, a); - a = init_builtin (builtin_type, "core:write", 1, (function1_t)&write_, a); - a = init_builtin (builtin_type, "core:write-error", 1, (function1_t)&write_error_, a); - a = init_builtin (builtin_type, "core:write-port", 2, (function1_t)&write_port_, a); - a = init_builtin (builtin_type, "exit", 1, (function1_t)&exit_, a); - a = init_builtin (builtin_type, "frame-printer", 1, (function1_t)&frame_printer, a); - a = init_builtin (builtin_type, "make-stack", -1, (function1_t)&make_stack, a); - a = init_builtin (builtin_type, "stack-length", 1, (function1_t)&stack_length, a); - a = init_builtin (builtin_type, "stack-ref", 2, (function1_t)&stack_ref, a); - a = init_builtin (builtin_type, "xassq", 2, (function1_t)&xassq, a); - a = init_builtin (builtin_type, "memq", 2, (function1_t)&memq, a); - a = init_builtin (builtin_type, "equal2?", 2, (function1_t)&equal2_p, a); - a = init_builtin (builtin_type, "last-pair", 1, (function1_t)&last_pair, a); - a = init_builtin (builtin_type, "pair?", 1, (function1_t)&pair_p, a); + a = init_builtin (builtin_type, "core:display", 1, (function1_t) & display_, a); + a = init_builtin (builtin_type, "core:display-error", 1, (function1_t) & display_error_, a); + a = init_builtin (builtin_type, "core:display-port", 2, (function1_t) & display_port_, a); + a = init_builtin (builtin_type, "core:write", 1, (function1_t) & write_, a); + a = init_builtin (builtin_type, "core:write-error", 1, (function1_t) & write_error_, a); + a = init_builtin (builtin_type, "core:write-port", 2, (function1_t) & write_port_, a); + a = init_builtin (builtin_type, "exit", 1, (function1_t) & exit_, a); + a = init_builtin (builtin_type, "frame-printer", 1, (function1_t) & frame_printer, a); + a = init_builtin (builtin_type, "make-stack", -1, (function1_t) & make_stack, a); + a = init_builtin (builtin_type, "stack-length", 1, (function1_t) & stack_length, a); + a = init_builtin (builtin_type, "stack-ref", 2, (function1_t) & stack_ref, a); + a = init_builtin (builtin_type, "xassq", 2, (function1_t) & xassq, a); + a = init_builtin (builtin_type, "memq", 2, (function1_t) & memq, a); + a = init_builtin (builtin_type, "equal2?", 2, (function1_t) & equal2_p, a); + a = init_builtin (builtin_type, "last-pair", 1, (function1_t) & last_pair, a); + a = init_builtin (builtin_type, "pair?", 1, (function1_t) & pair_p, a); // src/math.mes - a = init_builtin (builtin_type, ">", -1, (function1_t)&greater_p, a); - a = init_builtin (builtin_type, "<", -1, (function1_t)&less_p, a); - a = init_builtin (builtin_type, "=", -1, (function1_t)&is_p, a); - a = init_builtin (builtin_type, "-", -1, (function1_t)&minus, a); - a = init_builtin (builtin_type, "+", -1, (function1_t)&plus, a); - a = init_builtin (builtin_type, "/", -1, (function1_t)÷, a); - a = init_builtin (builtin_type, "modulo", 2, (function1_t)&modulo, a); - a = init_builtin (builtin_type, "*", -1, (function1_t)&multiply, a); - a = init_builtin (builtin_type, "logand", -1, (function1_t)&logand, a); - a = init_builtin (builtin_type, "logior", -1, (function1_t)&logior, a); - a = init_builtin (builtin_type, "lognot", 1, (function1_t)&lognot, a); - a = init_builtin (builtin_type, "logxor", -1, (function1_t)&logxor, a); - a = init_builtin (builtin_type, "ash", 2, (function1_t)&ash, a); + a = init_builtin (builtin_type, ">", -1, (function1_t) & greater_p, a); + a = init_builtin (builtin_type, "<", -1, (function1_t) & less_p, a); + a = init_builtin (builtin_type, "=", -1, (function1_t) & is_p, a); + a = init_builtin (builtin_type, "-", -1, (function1_t) & minus, a); + a = init_builtin (builtin_type, "+", -1, (function1_t) & plus, a); + a = init_builtin (builtin_type, "/", -1, (function1_t) & divide, a); + a = init_builtin (builtin_type, "modulo", 2, (function1_t) & modulo, a); + a = init_builtin (builtin_type, "*", -1, (function1_t) & multiply, a); + a = init_builtin (builtin_type, "logand", -1, (function1_t) & logand, a); + a = init_builtin (builtin_type, "logior", -1, (function1_t) & logior, a); + a = init_builtin (builtin_type, "lognot", 1, (function1_t) & lognot, a); + a = init_builtin (builtin_type, "logxor", -1, (function1_t) & logxor, a); + a = init_builtin (builtin_type, "ash", 2, (function1_t) & ash, a); // src/mes.mes - a = init_builtin (builtin_type, "core:make-cell", 3, (function1_t)&make_cell_, a); - a = init_builtin (builtin_type, "core:type", 1, (function1_t)&type_, a); - a = init_builtin (builtin_type, "core:car", 1, (function1_t)&car_, a); - a = init_builtin (builtin_type, "core:cdr", 1, (function1_t)&cdr_, a); - a = init_builtin (builtin_type, "cons", 2, (function1_t)&cons, a); - a = init_builtin (builtin_type, "car", 1, (function1_t)&car, a); - a = init_builtin (builtin_type, "cdr", 1, (function1_t)&cdr, a); - a = init_builtin (builtin_type, "list", -1, (function1_t)&list, a); - a = init_builtin (builtin_type, "null?", 1, (function1_t)&null_p, a); - a = init_builtin (builtin_type, "eq?", 2, (function1_t)&eq_p, a); - a = init_builtin (builtin_type, "values", -1, (function1_t)&values, a); - a = init_builtin (builtin_type, "acons", 3, (function1_t)&acons, a); - a = init_builtin (builtin_type, "length", 1, (function1_t)&length, a); - a = init_builtin (builtin_type, "error", 2, (function1_t)&error, a); - a = init_builtin (builtin_type, "append2", 2, (function1_t)&append2, a); - a = init_builtin (builtin_type, "append-reverse", 2, (function1_t)&append_reverse, a); - a = init_builtin (builtin_type, "core:reverse!", 2, (function1_t)&reverse_x_, a); - a = init_builtin (builtin_type, "pairlis", 3, (function1_t)&pairlis, a); - a = init_builtin (builtin_type, "assq", 2, (function1_t)&assq, a); - a = init_builtin (builtin_type, "assoc", 2, (function1_t)&assoc, a); - a = init_builtin (builtin_type, "set-car!", 2, (function1_t)&set_car_x, a); - a = init_builtin (builtin_type, "set-cdr!", 2, (function1_t)&set_cdr_x, a); - a = init_builtin (builtin_type, "set-env!", 3, (function1_t)&set_env_x, a); - a = init_builtin (builtin_type, "macro-get-handle", 1, (function1_t)¯o_get_handle, a); - a = init_builtin (builtin_type, "add-formals", 2, (function1_t)&add_formals, a); - a = init_builtin (builtin_type, "eval-apply", 0, (function1_t)&eval_apply, a); - a = init_builtin (builtin_type, "make-builtin-type", 0, (function1_t)&make_builtin_type, a); - a = init_builtin (builtin_type, "make-builtin", 4, (function1_t)&make_builtin, a); - a = init_builtin (builtin_type, "builtin-name", 1, (function1_t)&builtin_name, a); - a = init_builtin (builtin_type, "builtin-arity", 1, (function1_t)&builtin_arity, a); - a = init_builtin (builtin_type, "builtin?", 1, (function1_t)&builtin_p, a); - a = init_builtin (builtin_type, "builtin-printer", 1, (function1_t)&builtin_printer, a); + a = init_builtin (builtin_type, "core:make-cell", 3, (function1_t) & make_cell_, a); + a = init_builtin (builtin_type, "core:type", 1, (function1_t) & type_, a); + a = init_builtin (builtin_type, "core:car", 1, (function1_t) & car_, a); + a = init_builtin (builtin_type, "core:cdr", 1, (function1_t) & cdr_, a); + a = init_builtin (builtin_type, "cons", 2, (function1_t) & cons, a); + a = init_builtin (builtin_type, "car", 1, (function1_t) & car, a); + a = init_builtin (builtin_type, "cdr", 1, (function1_t) & cdr, a); + a = init_builtin (builtin_type, "list", -1, (function1_t) & list, a); + a = init_builtin (builtin_type, "null?", 1, (function1_t) & null_p, a); + a = init_builtin (builtin_type, "eq?", 2, (function1_t) & eq_p, a); + a = init_builtin (builtin_type, "values", -1, (function1_t) & values, a); + a = init_builtin (builtin_type, "acons", 3, (function1_t) & acons, a); + a = init_builtin (builtin_type, "length", 1, (function1_t) & length, a); + a = init_builtin (builtin_type, "error", 2, (function1_t) & error, a); + a = init_builtin (builtin_type, "append2", 2, (function1_t) & append2, a); + a = init_builtin (builtin_type, "append-reverse", 2, (function1_t) & append_reverse, a); + a = init_builtin (builtin_type, "core:reverse!", 2, (function1_t) & reverse_x_, a); + a = init_builtin (builtin_type, "pairlis", 3, (function1_t) & pairlis, a); + a = init_builtin (builtin_type, "assq", 2, (function1_t) & assq, a); + a = init_builtin (builtin_type, "assoc", 2, (function1_t) & assoc, a); + a = init_builtin (builtin_type, "set-car!", 2, (function1_t) & set_car_x, a); + a = init_builtin (builtin_type, "set-cdr!", 2, (function1_t) & set_cdr_x, a); + a = init_builtin (builtin_type, "set-env!", 3, (function1_t) & set_env_x, a); + a = init_builtin (builtin_type, "macro-get-handle", 1, (function1_t) & macro_get_handle, a); + a = init_builtin (builtin_type, "add-formals", 2, (function1_t) & add_formals, a); + a = init_builtin (builtin_type, "eval-apply", 0, (function1_t) & eval_apply, a); + a = init_builtin (builtin_type, "make-builtin-type", 0, (function1_t) & make_builtin_type, a); + a = init_builtin (builtin_type, "make-builtin", 4, (function1_t) & make_builtin, a); + a = init_builtin (builtin_type, "builtin-name", 1, (function1_t) & builtin_name, a); + a = init_builtin (builtin_type, "builtin-arity", 1, (function1_t) & builtin_arity, a); + a = init_builtin (builtin_type, "builtin?", 1, (function1_t) & builtin_p, a); + a = init_builtin (builtin_type, "builtin-printer", 1, (function1_t) & builtin_printer, a); // src/module.mes - a = init_builtin (builtin_type, "make-module-type", 0, (function1_t)&make_module_type, a); - a = init_builtin (builtin_type, "module-printer", 1, (function1_t)&module_printer, a); - a = init_builtin (builtin_type, "module-variable", 2, (function1_t)&module_variable, a); - a = init_builtin (builtin_type, "module-ref", 2, (function1_t)&module_ref, a); - a = init_builtin (builtin_type, "module-define!", 3, (function1_t)&module_define_x, a); + a = init_builtin (builtin_type, "make-module-type", 0, (function1_t) & make_module_type, a); + a = init_builtin (builtin_type, "module-printer", 1, (function1_t) & module_printer, a); + a = init_builtin (builtin_type, "module-variable", 2, (function1_t) & module_variable, a); + a = init_builtin (builtin_type, "module-ref", 2, (function1_t) & module_ref, a); + a = init_builtin (builtin_type, "module-define!", 3, (function1_t) & module_define_x, a); // src/posix.mes - a = init_builtin (builtin_type, "peek-byte", 0, (function1_t)&peek_byte, a); - a = init_builtin (builtin_type, "read-byte", 0, (function1_t)&read_byte, a); - a = init_builtin (builtin_type, "unread-byte", 1, (function1_t)&unread_byte, a); - a = init_builtin (builtin_type, "peek-char", 0, (function1_t)&peek_char, a); - a = init_builtin (builtin_type, "read-char", -1, (function1_t)&read_char, a); - a = init_builtin (builtin_type, "unread-char", 1, (function1_t)&unread_char, a); - a = init_builtin (builtin_type, "write-char", -1, (function1_t)&write_char, a); - a = init_builtin (builtin_type, "write-byte", -1, (function1_t)&write_byte, a); - a = init_builtin (builtin_type, "getenv", 1, (function1_t)&getenv_, a); - a = init_builtin (builtin_type, "setenv", 2, (function1_t)&setenv_, a); - a = init_builtin (builtin_type, "access?", 2, (function1_t)&access_p, a); - a = init_builtin (builtin_type, "current-input-port", 0, (function1_t)¤t_input_port, a); - a = init_builtin (builtin_type, "open-input-file", 1, (function1_t)&open_input_file, a); - a = init_builtin (builtin_type, "open-input-string", 1, (function1_t)&open_input_string, a); - a = init_builtin (builtin_type, "set-current-input-port", 1, (function1_t)&set_current_input_port, a); - a = init_builtin (builtin_type, "current-output-port", 0, (function1_t)¤t_output_port, a); - a = init_builtin (builtin_type, "current-error-port", 0, (function1_t)¤t_error_port, a); - a = init_builtin (builtin_type, "open-output-file", -1, (function1_t)&open_output_file, a); - a = init_builtin (builtin_type, "set-current-output-port", 1, (function1_t)&set_current_output_port, a); - a = init_builtin (builtin_type, "set-current-error-port", 1, (function1_t)&set_current_error_port, a); - a = init_builtin (builtin_type, "chmod", 2, (function1_t)&chmod_, a); - a = init_builtin (builtin_type, "isatty?", 1, (function1_t)&isatty_p, a); - a = init_builtin (builtin_type, "primitive-fork", 0, (function1_t)&primitive_fork, a); - a = init_builtin (builtin_type, "execl", 2, (function1_t)&execl_, a); - a = init_builtin (builtin_type, "core:waitpid", 2, (function1_t)&waitpid_, a); - a = init_builtin (builtin_type, "current-time", 0, (function1_t)¤t_time, a); - a = init_builtin (builtin_type, "gettimeofday", 0, (function1_t)&gettimeofday_, a); - a = init_builtin (builtin_type, "get-internal-run-time", 0, (function1_t)&get_internal_run_time, a); - a = init_builtin (builtin_type, "getcwd", 0, (function1_t)&getcwd_, a); - a = init_builtin (builtin_type, "dup", 1, (function1_t)&dup_, a); - a = init_builtin (builtin_type, "dup2", 2, (function1_t)&dup2_, a); - a = init_builtin (builtin_type, "delete-file", 1, (function1_t)&delete_file, a); + a = init_builtin (builtin_type, "peek-byte", 0, (function1_t) & peek_byte, a); + a = init_builtin (builtin_type, "read-byte", 0, (function1_t) & read_byte, a); + a = init_builtin (builtin_type, "unread-byte", 1, (function1_t) & unread_byte, a); + a = init_builtin (builtin_type, "peek-char", 0, (function1_t) & peek_char, a); + a = init_builtin (builtin_type, "read-char", -1, (function1_t) & read_char, a); + a = init_builtin (builtin_type, "unread-char", 1, (function1_t) & unread_char, a); + a = init_builtin (builtin_type, "write-char", -1, (function1_t) & write_char, a); + a = init_builtin (builtin_type, "write-byte", -1, (function1_t) & write_byte, a); + a = init_builtin (builtin_type, "getenv", 1, (function1_t) & getenv_, a); + a = init_builtin (builtin_type, "setenv", 2, (function1_t) & setenv_, a); + a = init_builtin (builtin_type, "access?", 2, (function1_t) & access_p, a); + a = init_builtin (builtin_type, "current-input-port", 0, (function1_t) & current_input_port, a); + a = init_builtin (builtin_type, "open-input-file", 1, (function1_t) & open_input_file, a); + a = init_builtin (builtin_type, "open-input-string", 1, (function1_t) & open_input_string, a); + a = init_builtin (builtin_type, "set-current-input-port", 1, (function1_t) & set_current_input_port, a); + a = init_builtin (builtin_type, "current-output-port", 0, (function1_t) & current_output_port, a); + a = init_builtin (builtin_type, "current-error-port", 0, (function1_t) & current_error_port, a); + a = init_builtin (builtin_type, "open-output-file", -1, (function1_t) & open_output_file, a); + a = init_builtin (builtin_type, "set-current-output-port", 1, (function1_t) & set_current_output_port, a); + a = init_builtin (builtin_type, "set-current-error-port", 1, (function1_t) & set_current_error_port, a); + a = init_builtin (builtin_type, "chmod", 2, (function1_t) & chmod_, a); + a = init_builtin (builtin_type, "isatty?", 1, (function1_t) & isatty_p, a); + a = init_builtin (builtin_type, "primitive-fork", 0, (function1_t) & primitive_fork, a); + a = init_builtin (builtin_type, "execl", 2, (function1_t) & execl_, a); + a = init_builtin (builtin_type, "core:waitpid", 2, (function1_t) & waitpid_, a); + a = init_builtin (builtin_type, "current-time", 0, (function1_t) & current_time, a); + a = init_builtin (builtin_type, "gettimeofday", 0, (function1_t) & gettimeofday_, a); + a = init_builtin (builtin_type, "get-internal-run-time", 0, (function1_t) & get_internal_run_time, a); + a = init_builtin (builtin_type, "getcwd", 0, (function1_t) & getcwd_, a); + a = init_builtin (builtin_type, "dup", 1, (function1_t) & dup_, a); + a = init_builtin (builtin_type, "dup2", 2, (function1_t) & dup2_, a); + a = init_builtin (builtin_type, "delete-file", 1, (function1_t) & delete_file, a); // src/reader.mes - a = init_builtin (builtin_type, "core:read-input-file-env", 2, (function1_t)&read_input_file_env_, a); - a = init_builtin (builtin_type, "read-input-file-env", 1, (function1_t)&read_input_file_env, a); - a = init_builtin (builtin_type, "read-env", 1, (function1_t)&read_env, a); - a = init_builtin (builtin_type, "reader-read-sexp", 3, (function1_t)&reader_read_sexp, a); - a = init_builtin (builtin_type, "reader-read-character", 0, (function1_t)&reader_read_character, a); - a = init_builtin (builtin_type, "reader-read-binary", 0, (function1_t)&reader_read_binary, a); - a = init_builtin (builtin_type, "reader-read-octal", 0, (function1_t)&reader_read_octal, a); - a = init_builtin (builtin_type, "reader-read-hex", 0, (function1_t)&reader_read_hex, a); - a = init_builtin (builtin_type, "reader-read-string", 0, (function1_t)&reader_read_string, a); + a = init_builtin (builtin_type, "core:read-input-file-env", 2, (function1_t) & read_input_file_env_, a); + a = init_builtin (builtin_type, "read-input-file-env", 1, (function1_t) & read_input_file_env, a); + a = init_builtin (builtin_type, "read-env", 1, (function1_t) & read_env, a); + a = init_builtin (builtin_type, "reader-read-sexp", 3, (function1_t) & reader_read_sexp, a); + a = init_builtin (builtin_type, "reader-read-character", 0, (function1_t) & reader_read_character, a); + a = init_builtin (builtin_type, "reader-read-binary", 0, (function1_t) & reader_read_binary, a); + a = init_builtin (builtin_type, "reader-read-octal", 0, (function1_t) & reader_read_octal, a); + a = init_builtin (builtin_type, "reader-read-hex", 0, (function1_t) & reader_read_hex, a); + a = init_builtin (builtin_type, "reader-read-string", 0, (function1_t) & reader_read_string, a); // src/strings.mes - a = init_builtin (builtin_type, "string=?", 2, (function1_t)&string_equal_p, a); - a = init_builtin (builtin_type, "symbol->string", 1, (function1_t)&symbol_to_string, a); - a = init_builtin (builtin_type, "symbol->keyword", 1, (function1_t)&symbol_to_keyword, a); - a = init_builtin (builtin_type, "keyword->string", 1, (function1_t)&keyword_to_string, a); - a = init_builtin (builtin_type, "string->symbol", 1, (function1_t)&string_to_symbol, a); - a = init_builtin (builtin_type, "make-symbol", 1, (function1_t)&make_symbol, a); - a = init_builtin (builtin_type, "string->list", 1, (function1_t)&string_to_list, a); - a = init_builtin (builtin_type, "list->string", 1, (function1_t)&list_to_string, a); - a = init_builtin (builtin_type, "read-string", -1, (function1_t)&read_string, a); - a = init_builtin (builtin_type, "string-append", -1, (function1_t)&string_append, a); - a = init_builtin (builtin_type, "string-length", 1, (function1_t)&string_length, a); - a = init_builtin (builtin_type, "string-ref", 2, (function1_t)&string_ref, a); + a = init_builtin (builtin_type, "string=?", 2, (function1_t) & string_equal_p, a); + a = init_builtin (builtin_type, "symbol->string", 1, (function1_t) & symbol_to_string, a); + a = init_builtin (builtin_type, "symbol->keyword", 1, (function1_t) & symbol_to_keyword, a); + a = init_builtin (builtin_type, "keyword->string", 1, (function1_t) & keyword_to_string, a); + a = init_builtin (builtin_type, "string->symbol", 1, (function1_t) & string_to_symbol, a); + a = init_builtin (builtin_type, "make-symbol", 1, (function1_t) & make_symbol, a); + a = init_builtin (builtin_type, "string->list", 1, (function1_t) & string_to_list, a); + a = init_builtin (builtin_type, "list->string", 1, (function1_t) & list_to_string, a); + a = init_builtin (builtin_type, "read-string", -1, (function1_t) & read_string, a); + a = init_builtin (builtin_type, "string-append", -1, (function1_t) & string_append, a); + a = init_builtin (builtin_type, "string-length", 1, (function1_t) & string_length, a); + a = init_builtin (builtin_type, "string-ref", 2, (function1_t) & string_ref, a); // src/struct.mes - a = init_builtin (builtin_type, "make-struct", 3, (function1_t)&make_struct, a); - a = init_builtin (builtin_type, "struct-length", 1, (function1_t)&struct_length, a); - a = init_builtin (builtin_type, "struct-ref", 2, (function1_t)&struct_ref, a); - a = init_builtin (builtin_type, "struct-set!", 3, (function1_t)&struct_set_x, a); + a = init_builtin (builtin_type, "make-struct", 3, (function1_t) & make_struct, a); + a = init_builtin (builtin_type, "struct-length", 1, (function1_t) & struct_length, a); + a = init_builtin (builtin_type, "struct-ref", 2, (function1_t) & struct_ref, a); + a = init_builtin (builtin_type, "struct-set!", 3, (function1_t) & struct_set_x, a); // src/vector.mes - a = init_builtin (builtin_type, "core:make-vector", 1, (function1_t)&make_vector_, a); - a = init_builtin (builtin_type, "vector-length", 1, (function1_t)&vector_length, a); - a = init_builtin (builtin_type, "vector-ref", 2, (function1_t)&vector_ref, a); - a = init_builtin (builtin_type, "vector-entry", 1, (function1_t)&vector_entry, a); - a = init_builtin (builtin_type, "vector-set!", 3, (function1_t)&vector_set_x, a); - a = init_builtin (builtin_type, "list->vector", 1, (function1_t)&list_to_vector, a); - a = init_builtin (builtin_type, "vector->list", 1, (function1_t)&vector_to_list, a); + a = init_builtin (builtin_type, "core:make-vector", 1, (function1_t) & make_vector_, a); + a = init_builtin (builtin_type, "vector-length", 1, (function1_t) & vector_length, a); + a = init_builtin (builtin_type, "vector-ref", 2, (function1_t) & vector_ref, a); + a = init_builtin (builtin_type, "vector-entry", 1, (function1_t) & vector_entry, a); + a = init_builtin (builtin_type, "vector-set!", 3, (function1_t) & vector_set_x, a); + a = init_builtin (builtin_type, "list->vector", 1, (function1_t) & list_to_vector, a); + a = init_builtin (builtin_type, "vector->list", 1, (function1_t) & vector_to_list, a); return a; } @@ -2203,7 +2218,7 @@ open_boot (char *prefix, char const *boot, char const *location) } SCM -read_boot () ///((internal)) +read_boot () ///((internal)) { __stdin = -1; char prefix[1024]; @@ -2350,7 +2365,9 @@ main (int argc, char *argv[]) module_printer (m0); if (g_debug > 3) { - eputs ("ports:"); write_error_ (g_ports); eputs ("\n"); + eputs ("ports:"); + write_error_ (g_ports); + eputs ("\n"); } eputs ("\n"); diff --git a/src/module.c b/src/module.c index 75978dca..e16839f5 100644 --- a/src/module.c +++ b/src/module.c @@ -23,9 +23,9 @@ SCM struct_set_x_ (SCM x, long i, SCM e); SCM cstring_to_symbol (char const *s); SCM -make_module_type () ///(internal)) +make_module_type () ///(internal)) { - SCM record_type = cell_symbol_record_type; // FIXME + SCM record_type = cell_symbol_record_type; // FIXME SCM fields = cell_nil; fields = cons (cstring_to_symbol ("globals"), fields); fields = cons (cstring_to_symbol ("locals"), fields); @@ -36,7 +36,7 @@ make_module_type () ///(internal)) } SCM -make_initial_module (SCM a) ///((internal)) +make_initial_module (SCM a) ///((internal)) { SCM module_type = make_module_type (); a = acons (cell_symbol_module, module_type, a); @@ -71,9 +71,15 @@ SCM module_printer (SCM module) { //module = m0; - fdputs ("#<", __stdout); display_ (struct_ref_ (module, 2)); fdputc (' ', __stdout); - fdputs ("name: ", __stdout); display_ (struct_ref_ (module, 3)); fdputc (' ', __stdout); - fdputs ("locals: ", __stdout); display_ (struct_ref_ (module, 4)); fdputc (' ', __stdout); + fdputs ("#<", __stdout); + display_ (struct_ref_ (module, 2)); + fdputc (' ', __stdout); + fdputs ("name: ", __stdout); + display_ (struct_ref_ (module, 3)); + fdputc (' ', __stdout); + fdputs ("locals: ", __stdout); + display_ (struct_ref_ (module, 4)); + fdputc (' ', __stdout); SCM table = struct_ref_ (module, 5); fdputs ("globals:\n ", __stdout); display_ (table); diff --git a/src/posix.c b/src/posix.c index 3470e832..4a10a279 100644 --- a/src/posix.c +++ b/src/posix.c @@ -60,7 +60,7 @@ readchar () return -1; char const *p = CSTRING (string); int c = *p++; - STRING (port) = make_string (p, length-1); + STRING (port) = make_string (p, length - 1); return c; } @@ -74,7 +74,7 @@ unreadchar (int c) size_t length = LENGTH (string); char *p = CSTRING (string); p--; - string = make_string (p, length+1); + string = make_string (p, length + 1); p = CSTRING (string); p[0] = c; STRING (port) = string; @@ -107,7 +107,7 @@ peek_char () } SCM -read_char (SCM port) ///((arity . n)) +read_char (SCM port) ///((arity . n)) { int fd = __stdin; if (TYPE (port) == TPAIR && TYPE (car (port)) == TNUMBER) @@ -125,14 +125,14 @@ unread_char (SCM i) } SCM -write_char (SCM i) ///((arity . n)) +write_char (SCM i) ///((arity . n)) { write_byte (i); return i; } SCM -write_byte (SCM x) ///((arity . n)) +write_byte (SCM x) ///((arity . n)) { SCM c = car (x); SCM p = cdr (x); @@ -142,7 +142,7 @@ write_byte (SCM x) ///((arity . n)) if (TYPE (p) == TPAIR && TYPE (car (p)) == TNUMBER && VALUE (CAR (p)) == 2) fd = __stderr; char cc = VALUE (c); - write (fd, (char*)&cc, 1); + write (fd, (char *) &cc, 1); #if !__MESC__ assert (TYPE (c) == TNUMBER || TYPE (c) == TCHAR); #endif @@ -150,7 +150,7 @@ write_byte (SCM x) ///((arity . n)) } SCM -getenv_ (SCM s) ///((name . "getenv")) +getenv_ (SCM s) ///((name . "getenv")) { char *p; p = getenv (CSTRING (s)); @@ -158,7 +158,7 @@ getenv_ (SCM s) ///((name . "getenv")) } SCM -setenv_ (SCM s, SCM v) ///((name . "setenv")) +setenv_ (SCM s, SCM v) ///((name . "setenv")) { char buf[1024]; strcpy (buf, CSTRING (s)); @@ -221,14 +221,14 @@ current_error_port () } SCM -open_output_file (SCM x) ///((arity . n)) +open_output_file (SCM x) ///((arity . n)) { SCM file_name = car (x); x = cdr (x); - int mode = S_IRUSR|S_IWUSR; + int mode = S_IRUSR | S_IWUSR; if (TYPE (x) == TPAIR && TYPE (car (x)) == TNUMBER) mode = VALUE (car (x)); - return MAKE_NUMBER (mes_open (CSTRING (file_name), O_WRONLY|O_CREAT|O_TRUNC, mode)); + return MAKE_NUMBER (mes_open (CSTRING (file_name), O_WRONLY | O_CREAT | O_TRUNC, mode)); } SCM @@ -246,7 +246,7 @@ set_current_error_port (SCM port) } SCM -chmod_ (SCM file_name, SCM mode) ///((name . "chmod")) +chmod_ (SCM file_name, SCM mode) ///((name . "chmod")) { chmod (CSTRING (file_name), VALUE (mode)); return cell_unspecified; @@ -265,16 +265,14 @@ primitive_fork () } SCM -execl_ (SCM file_name, SCM args) ///((name . "execl")) +execl_ (SCM file_name, SCM args) ///((name . "execl")) { char *c_argv[1000]; // POSIX minimum 4096 int i = 0; if (length__ (args) > 1000) error (cell_symbol_system_error, - cons (file_name, - cons (MAKE_STRING0 ("too many arguments"), - cons (file_name, args)))); + cons (file_name, cons (MAKE_STRING0 ("too many arguments"), cons (file_name, args)))); c_argv[i++] = CSTRING (file_name); while (args != cell_nil) { @@ -283,7 +281,11 @@ execl_ (SCM file_name, SCM args) ///((name . "execl")) args = CDR (args); if (g_debug > 2) { - eputs ("arg["); eputs (itoa (i)); eputs ("]: "); eputs (c_argv[i-1]); eputs ("\n"); + eputs ("arg["); + eputs (itoa (i)); + eputs ("]: "); + eputs (c_argv[i - 1]); + eputs ("\n"); } } c_argv[i] = 0; @@ -308,7 +310,7 @@ waitpid_ (SCM pid, SCM options) struct timespec g_start_time; SCM -init_time (SCM a) ///((internal)) +init_time (SCM a) ///((internal)) { clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &g_start_time); a = acons (cell_symbol_internal_time_units_per_second, MAKE_NUMBER (TIME_UNITS_PER_SECOND), a); @@ -321,7 +323,7 @@ current_time () } SCM -gettimeofday_ () ///((name . "gettimeofday")) +gettimeofday_ () ///((name . "gettimeofday")) { struct timeval time; gettimeofday (&time, 0); @@ -331,8 +333,7 @@ gettimeofday_ () ///((name . "gettimeofday")) long seconds_and_nanoseconds_to_long (long s, long ns) { - return s * TIME_UNITS_PER_SECOND - + ns / (1000000000 / TIME_UNITS_PER_SECOND); + return s * TIME_UNITS_PER_SECOND + ns / (1000000000 / TIME_UNITS_PER_SECOND); } SCM @@ -346,20 +347,20 @@ get_internal_run_time () } SCM -getcwd_ () ///((name . "getcwd")) +getcwd_ () ///((name . "getcwd")) { char buf[PATH_MAX]; return MAKE_STRING0 (getcwd (buf, PATH_MAX)); } SCM -dup_ (SCM port) ///((name . "dup")) +dup_ (SCM port) ///((name . "dup")) { return MAKE_NUMBER (dup (VALUE (port))); } SCM -dup2_ (SCM old, SCM new) ///((name . "dup2")) +dup2_ (SCM old, SCM new) ///((name . "dup2")) { dup2 (VALUE (old), VALUE (new)); return cell_unspecified; diff --git a/src/reader.c b/src/reader.c index 2f0783e6..ccface38 100644 --- a/src/reader.c +++ b/src/reader.c @@ -46,8 +46,7 @@ reader_read_line_comment (int c) return c; c = readchar (); } - error (cell_symbol_system_error, - MAKE_STRING0 ("reader_read_line_comment")); + error (cell_symbol_system_error, MAKE_STRING0 ("reader_read_line_comment")); } SCM reader_read_block_comment (int s, int c); @@ -127,22 +126,18 @@ reset_reader: if (c == '#') return reader_read_hash (readchar (), a); if (c == '`') - return cons (cell_symbol_quasiquote, - cons (reader_read_sexp_ (readchar (), a), cell_nil)); - if(c == ',') + return cons (cell_symbol_quasiquote, cons (reader_read_sexp_ (readchar (), a), cell_nil)); + if (c == ',') { if (peekchar () == '@') { readchar (); - return cons (cell_symbol_unquote_splicing, - cons (reader_read_sexp_ (readchar (), a), cell_nil)); + return cons (cell_symbol_unquote_splicing, cons (reader_read_sexp_ (readchar (), a), cell_nil)); } - return cons (cell_symbol_unquote, - cons (reader_read_sexp_ (readchar (), a), cell_nil)); + return cons (cell_symbol_unquote, cons (reader_read_sexp_ (readchar (), a), cell_nil)); } if (c == '\'') - return cons (cell_symbol_quote, - cons (reader_read_sexp_ (readchar (), a), cell_nil)); + return cons (cell_symbol_quote, cons (reader_read_sexp_ (readchar (), a), cell_nil)); if (c == '"') return reader_read_string (); if (c == '.' && (!reader_identifier_p (peekchar ()))) @@ -159,7 +154,7 @@ reader_eat_whitespace (int c) return reader_eat_whitespace (reader_read_line_comment (c)); if (c == '#' && (peekchar () == '!' || peekchar () == '|')) { - c=readchar (); + c = readchar (); reader_read_block_comment (c, readchar ()); return reader_eat_whitespace (readchar ()); } @@ -174,7 +169,7 @@ reader_read_list (int c, SCM a) return cell_nil; if (c == EOF) error (cell_symbol_not_a_pair, MAKE_STRING0 ("EOF in list")); - //return cell_nil; + //return cell_nil; SCM s = reader_read_sexp_ (c, a); if (s == cell_dot) return CAR (reader_read_list (readchar (), a)); @@ -190,7 +185,8 @@ read_env (SCM a) SCM reader_read_block_comment (int s, int c) { - if (c == s && peekchar () == '#') return readchar (); + if (c == s && peekchar () == '#') + return readchar (); return reader_read_block_comment (s, readchar ()); } @@ -207,28 +203,24 @@ reader_read_hash (int c, SCM a) reader_read_block_comment (c, readchar ()); return reader_read_sexp_ (readchar (), a); } - if(c == 'f') + if (c == 'f') return cell_f; - if(c == 't') + if (c == 't') return cell_t; - if(c == ',') + if (c == ',') { if (peekchar () == '@') { readchar (); - return cons (cell_symbol_unsyntax_splicing, - cons (reader_read_sexp_ (readchar (), a), cell_nil)); + return cons (cell_symbol_unsyntax_splicing, cons (reader_read_sexp_ (readchar (), a), cell_nil)); } - return cons (cell_symbol_unsyntax, - cons (reader_read_sexp_ (readchar (), a), cell_nil)); + return cons (cell_symbol_unsyntax, cons (reader_read_sexp_ (readchar (), a), cell_nil)); } if (c == '\'') - return cons (cell_symbol_syntax, - cons (reader_read_sexp_ (readchar (), a), cell_nil)); + return cons (cell_symbol_syntax, cons (reader_read_sexp_ (readchar (), a), cell_nil)); if (c == '`') - return cons (cell_symbol_quasisyntax, - cons (reader_read_sexp_ (readchar (), a), cell_nil)); + return cons (cell_symbol_quasisyntax, cons (reader_read_sexp_ (readchar (), a), cell_nil)); if (c == ':') { SCM x = reader_read_identifier_or_number (readchar ()); @@ -267,8 +259,7 @@ reader_read_character () int c = readchar (); int p = peekchar (); int i = 0; - if (c >= '0' && c <= '7' - && p >= '0' && p <= '7') + if (c >= '0' && c <= '7' && p >= '0' && p <= '7') { c = c - '0'; while (p >= '0' && p <= '7') @@ -278,62 +269,74 @@ reader_read_character () p = peekchar (); } } - else if (c == 'x' - && ((p >= '0' && p <= '9') - || (p >= 'a' && p <= 'f') - || (p >= 'F' && p <= 'F'))) + else if (c == 'x' && ((p >= '0' && p <= '9') || (p >= 'a' && p <= 'f') || (p >= 'F' && p <= 'F'))) { c = VALUE (reader_read_hex ()); eputs ("reading hex c="); eputs (itoa (c)); eputs ("\n"); } - else if (((c >= 'a' && c <= 'z') - || c == '*') - && ((p >= 'a' && p <= 'z') - || p == '*')) + else if (((c >= 'a' && c <= 'z') || c == '*') && ((p >= 'a' && p <= 'z') || p == '*')) { char buf[10]; buf[i] = c; i = i + 1; - while ((p >= 'a' && p <= 'z') - || p == '*') + while ((p >= 'a' && p <= 'z') || p == '*') { buf[i] = readchar (); i = i + 1; p = peekchar (); } buf[i] = 0; - if (!strcmp (buf, "*eof*")) c = EOF; - else if (!strcmp (buf, "nul")) c = '\0'; - else if (!strcmp (buf, "alarm")) c = '\a'; - else if (!strcmp (buf, "backspace")) c = '\b'; - else if (!strcmp (buf, "tab")) c = '\t'; - else if (!strcmp (buf, "linefeed")) c = '\n'; - else if (!strcmp (buf, "newline")) c = '\n'; - else if (!strcmp (buf, "vtab")) c = '\v'; - else if (!strcmp (buf, "page")) c = '\f'; -#if 1 //__MESC__ + if (!strcmp (buf, "*eof*")) + c = EOF; + else if (!strcmp (buf, "nul")) + c = '\0'; + else if (!strcmp (buf, "alarm")) + c = '\a'; + else if (!strcmp (buf, "backspace")) + c = '\b'; + else if (!strcmp (buf, "tab")) + c = '\t'; + else if (!strcmp (buf, "linefeed")) + c = '\n'; + else if (!strcmp (buf, "newline")) + c = '\n'; + else if (!strcmp (buf, "vtab")) + c = '\v'; + else if (!strcmp (buf, "page")) + c = '\f'; +#if 1 //__MESC__ //Nyacc bug - else if (!strcmp (buf, "return")) c = 13; - else if (!strcmp (buf, "esc")) c = 27; + else if (!strcmp (buf, "return")) + c = 13; + else if (!strcmp (buf, "esc")) + c = 27; #else - else if (!strcmp (buf, "return")) c = '\r'; + else if (!strcmp (buf, "return")) + c = '\r'; //Nyacc crash else if (!strcmp (buf, "esc")) c = '\e'; #endif - else if (!strcmp (buf, "space")) c = ' '; + else if (!strcmp (buf, "space")) + c = ' '; -#if 1 // Nyacc uses old abbrevs - else if (!strcmp (buf, "bel")) c = '\a'; - else if (!strcmp (buf, "bs")) c = '\b'; - else if (!strcmp (buf, "ht")) c = '\t'; - else if (!strcmp (buf, "vt")) c = '\v'; +#if 1 // Nyacc uses old abbrevs + else if (!strcmp (buf, "bel")) + c = '\a'; + else if (!strcmp (buf, "bs")) + c = '\b'; + else if (!strcmp (buf, "ht")) + c = '\t'; + else if (!strcmp (buf, "vt")) + c = '\v'; -#if 1 //__MESC__ +#if 1 //__MESC__ //Nyacc bug - else if (!strcmp (buf, "cr")) c = 13; + else if (!strcmp (buf, "cr")) + c = 13; #else - else if (!strcmp (buf, "cr")) c = '\r'; + else if (!strcmp (buf, "cr")) + c = '\r'; #endif #endif // Nyacc uses old abbrevs @@ -342,8 +345,7 @@ reader_read_character () eputs ("char not supported: "); eputs (buf); eputs ("\n"); - error (cell_symbol_system_error, - MAKE_STRING0 ("char not supported")); + error (cell_symbol_system_error, MAKE_STRING0 ("char not supported")); } } return MAKE_CHAR (c); @@ -409,9 +411,7 @@ reader_read_hex () readchar (); c = peekchar (); } - while ((c >= '0' && c <= '9') - || (c >= 'A' && c <= 'F') - || (c >= 'a' && c <= 'f')) + while ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) { n = n << 4; if (c >= 'a') diff --git a/src/string.c b/src/string.c index b1e17022..3506c6bc 100644 --- a/src/string.c +++ b/src/string.c @@ -19,7 +19,7 @@ */ void -assert_max_string (size_t i, char const* msg, char* string) +assert_max_string (size_t i, char const *msg, char *string) { if (i > MAX_STRING) { @@ -27,14 +27,14 @@ assert_max_string (size_t i, char const* msg, char* string) eputs (":string too long["); eputs (itoa (i)); eputs ("]:"); - string[MAX_STRING-1] = 0; + string[MAX_STRING - 1] = 0; eputs (string); error (cell_symbol_system_error, cell_f); } } -char const* -list_to_cstring (SCM list, size_t* size) +char const * +list_to_cstring (SCM list, size_t * size) { size_t i = 0; char *p = g_buf; @@ -57,25 +57,25 @@ bytes_cells (size_t length) } SCM -make_bytes (char const* s, size_t length) +make_bytes (char const *s, size_t length) { size_t size = bytes_cells (length); SCM x = alloc (size); TYPE (x) = TBYTES; LENGTH (x) = length; - char *p = (char*)&g_cells[x].cdr; + char *p = (char *) &g_cells[x].cdr; if (!length) - *(char*)p = 0; + *(char *) p = 0; else memcpy (p, s, length + 1); return x; } SCM -make_string (char const* s, size_t length) +make_string (char const *s, size_t length) { if (length > MAX_STRING) - assert_max_string (length, "make_string", (char*)s); + assert_max_string (length, "make_string", (char *) s); SCM x = make_cell__ (TSTRING, length, 0); SCM v = make_bytes (s, length); CDR (x) = v; @@ -83,23 +83,28 @@ make_string (char const* s, size_t length) } SCM -string_equal_p (SCM a, SCM b) ///((name . "string=?")) +string_equal_p (SCM a, SCM b) ///((name . "string=?")) { - if (! ((TYPE (a) == TSTRING && TYPE (b) == TSTRING) - || (TYPE (a) == TKEYWORD || TYPE (b) == TKEYWORD))) + if (!((TYPE (a) == TSTRING && TYPE (b) == TSTRING) || (TYPE (a) == TKEYWORD || TYPE (b) == TKEYWORD))) { - eputs ("type a: "); eputs (itoa (TYPE (a))); eputs ("\n"); - eputs ("type b: "); eputs (itoa (TYPE (b))); eputs ("\n"); - eputs ("a= "); write_error_ (a); eputs ("\n"); - eputs ("b= "); write_error_ (b); eputs ("\n"); - assert ((TYPE (a) == TSTRING && TYPE (b) == TSTRING) - || (TYPE (a) == TKEYWORD || TYPE (b) == TKEYWORD)); + eputs ("type a: "); + eputs (itoa (TYPE (a))); + eputs ("\n"); + eputs ("type b: "); + eputs (itoa (TYPE (b))); + eputs ("\n"); + eputs ("a= "); + write_error_ (a); + eputs ("\n"); + eputs ("b= "); + write_error_ (b); + eputs ("\n"); + assert ((TYPE (a) == TSTRING && TYPE (b) == TSTRING) || (TYPE (a) == TKEYWORD || TYPE (b) == TKEYWORD)); } if (a == b || STRING (a) == STRING (b) || (!LENGTH (a) && !LENGTH (b)) - || (LENGTH (a) == LENGTH (b) - && !memcmp (CSTRING (a), CSTRING (b), LENGTH (a)))) + || (LENGTH (a) == LENGTH (b) && !memcmp (CSTRING (a), CSTRING (b), LENGTH (a)))) return cell_t; return cell_f; } @@ -140,7 +145,7 @@ make_symbol (SCM string) } SCM -bytes_to_list (char const* s, size_t i) +bytes_to_list (char const *s, size_t i) { SCM p = cell_nil; while (i--) @@ -152,7 +157,7 @@ bytes_to_list (char const* s, size_t i) } SCM -cstring_to_list (char const* s) +cstring_to_list (char const *s) { return bytes_to_list (s, strlen (s)); } @@ -179,7 +184,7 @@ list_to_string (SCM list) } SCM -read_string (SCM port) ///((arity . n)) +read_string (SCM port) ///((arity . n)) { int fd = __stdin; if (TYPE (port) == TPAIR && TYPE (car (port)) == TNUMBER) @@ -199,7 +204,7 @@ read_string (SCM port) ///((arity . n)) } SCM -string_append (SCM x) ///((arity . n)) +string_append (SCM x) ///((arity . n)) { char *p = g_buf; g_buf[0] = 0; diff --git a/src/struct.c b/src/struct.c index dea9fdc2..0eb9be91 100644 --- a/src/struct.c +++ b/src/struct.c @@ -30,8 +30,8 @@ make_struct (SCM type, SCM fields, SCM printer) SCM v = alloc (size); SCM x = make_cell__ (TSTRUCT, size, v); g_cells[v] = g_cells[vector_entry (type)]; - g_cells[v+1] = g_cells[vector_entry (printer)]; - for (long i=2; i