mes: Run build-aux/indent.sh.

* src/mes.c: Re-indent.
* src: Likewise.
* include: Likewise.
* lib: Likewise.
* scaffold: Likewise.
This commit is contained in:
Jan Nieuwenhuizen 2019-05-18 13:27:42 +02:00
parent a46c318bb8
commit c33d6d00bc
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
270 changed files with 2900 additions and 2110 deletions

View file

@ -26,4 +26,3 @@
#endif // (WITH_GLIBC) #endif // (WITH_GLIBC)
#endif // __MES_FEATURES_H #endif // __MES_FEATURES_H

View file

@ -26,4 +26,3 @@
#endif // (WITH_GLIBC) #endif // (WITH_GLIBC)
#endif // __MES_STRINGS_H #endif // __MES_STRINGS_H

View file

@ -26,4 +26,3 @@
#endif // (WITH_GLIBC) #endif // (WITH_GLIBC)
#endif // __MES_SYS_CDEFS_H #endif // __MES_SYS_CDEFS_H

View file

@ -33,4 +33,3 @@ int ioctl (int fd, unsigned long request, ...);
#endif // ! WITH_GLIBC #endif // ! WITH_GLIBC
#endif // __MES_SYS_IOCTL_H #endif // __MES_SYS_IOCTL_H

View file

@ -28,4 +28,3 @@ typedef int fd_set;
#endif //! WITH_GLIBC #endif //! WITH_GLIBC
#endif // __MES_SYS_SELECT_H #endif // __MES_SYS_SELECT_H

View file

@ -26,4 +26,3 @@
#endif // (WITH_GLIBC) #endif // (WITH_GLIBC)
#endif // __MES_SYS_TIMEB_H #endif // __MES_SYS_TIMEB_H

View file

@ -26,4 +26,3 @@
#endif // (WITH_GLIBC) #endif // (WITH_GLIBC)
#endif // __MES_SYS_UCONTEXT_H #endif // __MES_SYS_UCONTEXT_H

View file

@ -31,7 +31,8 @@ typedef long int clockid_t;
typedef long int time_t; typedef long int time_t;
#endif #endif
struct tm { struct tm
{
int tm_sec; int tm_sec;
int tm_min; int tm_min;
int tm_hour; int tm_hour;

View file

@ -79,7 +79,8 @@ readdir (DIR *dirp)
dirp->filepos = dp->d_off; dirp->filepos = dp->d_off;
/* Skip deleted files. */ /* Skip deleted files. */
} while (dp->d_ino == 0); }
while (dp->d_ino == 0);
return dp; return dp;
} }

View file

@ -19,8 +19,7 @@
*/ */
int int
nanosleep (const struct timespec *requested_time, nanosleep (const struct timespec *requested_time, struct timespec *remaining)
struct timespec *remaining)
{ {
return _sys_call2 (SYS_nanosleep, (long) requested_time, (long) remaining); return _sys_call2 (SYS_nanosleep, (long) requested_time, (long) remaining);
} }

View file

@ -26,12 +26,19 @@ read (int filedes, void *buffer, size_t size)
{ {
if (bytes == 1) 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 else
{ {
eputs ("read fd="); eputs (itoa ((int)filedes)); eputs ("read fd=");
eputs (" bytes="); eputs (itoa (bytes)); eputs ("\n"); eputs (itoa ((int) filedes));
eputs (" bytes=");
eputs (itoa (bytes));
eputs ("\n");
} }
} }
return bytes; return bytes;

View file

@ -19,8 +19,7 @@
*/ */
int int
setitimer (int which, struct itimerval const *new, setitimer (int which, struct itimerval const *new, struct itimerval *old)
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);
} }

View file

@ -40,7 +40,8 @@ ntoab (long x, int base, int signed_p)
long i = u % base; long i = u % base;
*p-- = i > 9 ? 'a' + i - 10 : '0' + i; *p-- = i > 9 ? 'a' + i - 10 : '0' + i;
u = u / base; u = u / base;
} while (u); }
while (u);
if (sign && *(p + 1) != '0') if (sign && *(p + 1) != '0')
*p-- = '-'; *p-- = '-';

View file

@ -27,7 +27,9 @@ search_path (char const *file_name)
char *path = getenv ("PATH"); char *path = getenv ("PATH");
if (__mes_debug ()) if (__mes_debug ())
{ {
eputs ("\n search-path: "); eputs (file_name); eputs ("\n"); eputs ("\n search-path: ");
eputs (file_name);
eputs ("\n");
} }
while (*path) while (*path)
{ {
@ -38,7 +40,9 @@ search_path (char const *file_name)
buf[end - path] = 0; buf[end - path] = 0;
if (__mes_debug ()) if (__mes_debug ())
{ {
eputs (" dir: "); eputs (buf); eputs ("\n"); eputs (" dir: ");
eputs (buf);
eputs ("\n");
} }
if (buf[end - path] != '/') if (buf[end - path] != '/')
strcat (buf, "/"); strcat (buf, "/");
@ -47,7 +51,9 @@ search_path (char const *file_name)
{ {
if (__mes_debug ()) if (__mes_debug ())
{ {
eputs (" found: "); eputs (buf); eputs ("\n"); eputs (" found: ");
eputs (buf);
eputs ("\n");
} }
return buf; return buf;
} }

View file

@ -26,7 +26,9 @@ execl (char const *file_name, char const *arg, ...)
{ {
if (__mes_debug () > 2) 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; int i = 0;
@ -42,7 +44,11 @@ execl (char const *file_name, char const *arg, ...)
arg = va_arg (ap, char const *); arg = va_arg (ap, char const *);
if (__mes_debug () > 2) 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; argv[i] = 0;

View file

@ -33,11 +33,17 @@ execvp (char const *file_name, char *const argv[])
} }
if (__mes_debug ()) if (__mes_debug ())
{ {
eputs (" EXEC: "); eputs (file_name); eputs ("\n"); eputs (" EXEC: ");
eputs (file_name);
eputs ("\n");
int i = 0; int i = 0;
while (argv[i]) 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++; i++;
} }
} }

View file

@ -58,8 +58,8 @@ static char *nextchar;
for unrecognized options. */ for unrecognized options. */
int opterr = 1; int opterr = 1;
/* Handle permutation of arguments. */ /* Handle permutation of arguments. */
/* Describe the part of ARGV that contains non-options that have /* Describe the part of ARGV that contains non-options that have
@ -68,8 +68,8 @@ int opterr = 1;
static int first_nonopt; static int first_nonopt;
static int last_nonopt; static int last_nonopt;
/* Scan elements of ARGV (whose length is ARGC) for option characters /* Scan elements of ARGV (whose length is ARGC) for option characters
given in OPTSTRING. given in OPTSTRING.
@ -168,13 +168,10 @@ _getopt_internal (int argc, char *const
/* We have found another option-ARGV-element. /* We have found another option-ARGV-element.
Start decoding its characters. */ Start decoding its characters. */
nextchar = (argv[optind] + 1 nextchar = (argv[optind] + 1 + (longopts != NULL && argv[optind][1] == '-'));
+ (longopts != NULL && argv[optind][1] == '-'));
} }
if (longopts != NULL if (longopts != NULL && ((argv[optind][0] == '-' && (argv[optind][1] == '-' || long_only))))
&& ((argv[optind][0] == '-'
&& (argv[optind][1] == '-' || long_only))))
{ {
const struct option *p; const struct option *p;
char *s = nextchar; char *s = nextchar;
@ -187,8 +184,7 @@ _getopt_internal (int argc, char *const
s++; s++;
/* Test all options for either exact match or abbreviated matches. */ /* Test all options for either exact match or abbreviated matches. */
for (p = longopts, option_index = 0; p->name; for (p = longopts, option_index = 0; p->name; p++, option_index++)
p++, option_index++)
if (!strncmp (p->name, nextchar, s - nextchar)) if (!strncmp (p->name, nextchar, s - nextchar))
{ {
if (s - nextchar == strlen (p->name)) if (s - nextchar == strlen (p->name))
@ -213,8 +209,7 @@ _getopt_internal (int argc, char *const
if (ambig && !exact) if (ambig && !exact)
{ {
if (opterr) if (opterr)
fprintf (stderr, "%s: option `%s' is ambiguous\n", fprintf (stderr, "%s: option `%s' is ambiguous\n", argv[0], argv[optind]);
argv[0], argv[optind]);
nextchar += strlen (nextchar); nextchar += strlen (nextchar);
optind++; optind++;
return '?'; return '?';
@ -237,8 +232,7 @@ _getopt_internal (int argc, char *const
if (argv[optind - 1][1] == '-') if (argv[optind - 1][1] == '-')
/* --option */ /* --option */
fprintf (stderr, fprintf (stderr,
"%s: option `--%s' doesn't allow an argument\n", "%s: option `--%s' doesn't allow an argument\n", argv[0], pfound->name);
argv[0], pfound->name);
else else
/* +option or -option */ /* +option or -option */
fprintf (stderr, fprintf (stderr,
@ -256,8 +250,7 @@ _getopt_internal (int argc, char *const
else else
{ {
if (opterr) if (opterr)
fprintf (stderr, "%s: option `%s' requires an argument\n", fprintf (stderr, "%s: option `%s' requires an argument\n", argv[0], argv[optind - 1]);
argv[0], argv[optind - 1]);
nextchar += strlen (nextchar); nextchar += strlen (nextchar);
return '?'; return '?';
} }
@ -276,19 +269,16 @@ _getopt_internal (int argc, char *const
or the option starts with '--' or is not a valid short or the option starts with '--' or is not a valid short
option, then it's an error. option, then it's an error.
Otherwise interpret it as a short option. */ Otherwise interpret it as a short option. */
if (!long_only || argv[optind][1] == '-' if (!long_only || argv[optind][1] == '-' || strchr (optstring, *nextchar) == NULL)
|| strchr (optstring, *nextchar) == NULL)
{ {
if (opterr) if (opterr)
{ {
if (argv[optind][1] == '-') if (argv[optind][1] == '-')
/* --option */ /* --option */
fprintf (stderr, "%s: unrecognized option `--%s'\n", fprintf (stderr, "%s: unrecognized option `--%s'\n", argv[0], nextchar);
argv[0], nextchar);
else else
/* +option or -option */ /* +option or -option */
fprintf (stderr, "%s: unrecognized option `%c%s'\n", fprintf (stderr, "%s: unrecognized option `%c%s'\n", argv[0], argv[optind][0], nextchar);
argv[0], argv[optind][0], nextchar);
} }
nextchar += strlen (nextchar); nextchar += strlen (nextchar);
optind++; optind++;
@ -311,8 +301,7 @@ _getopt_internal (int argc, char *const
if (opterr) if (opterr)
{ {
if (c < 040 || c >= 0177) if (c < 040 || c >= 0177)
fprintf (stderr, "%s: unrecognized option, character code 0%o\n", fprintf (stderr, "%s: unrecognized option, character code 0%o\n", argv[0], c);
argv[0], c);
else else
fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c); fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
} }
@ -345,8 +334,7 @@ _getopt_internal (int argc, char *const
else if (optind == argc) else if (optind == argc)
{ {
if (opterr) if (opterr)
fprintf (stderr, "%s: option `-%c' requires an argument\n", fprintf (stderr, "%s: option `-%c' requires an argument\n", argv[0], c);
argv[0], c);
c = '?'; c = '?';
} }
else else
@ -363,8 +351,7 @@ _getopt_internal (int argc, char *const
int int
getopt (int argc, char *const *argv, char const *options) getopt (int argc, char *const *argv, char const *options)
{ {
return _getopt_internal (argc, argv, options, return _getopt_internal (argc, argv, options, (const struct option *) 0, (int *) 0, 0);
(const struct option *) 0, (int *) 0, 0);
} }
int int

View file

@ -33,14 +33,16 @@ fopen (char const *file_name, char const *opentype)
{ {
if (__mes_debug ()) if (__mes_debug ())
{ {
eputs ("fopen "); eputs (file_name); eputs ("fopen ");
eputs (" "); eputs (opentype); eputs ("\n"); eputs (file_name);
eputs (" ");
eputs (opentype);
eputs ("\n");
} }
int fd; int fd;
int mode = 0600; int mode = 0600;
if ((opentype[0] == 'a' || !strcmp (opentype, "r+")) if ((opentype[0] == 'a' || !strcmp (opentype, "r+")) && !access (file_name, O_RDONLY))
&& !access (file_name, O_RDONLY))
{ {
int flags = O_RDWR; int flags = O_RDWR;
if (opentype[0] == 'a') if (opentype[0] == 'a')
@ -58,7 +60,9 @@ fopen (char const *file_name, char const *opentype)
if (__mes_debug ()) if (__mes_debug ())
{ {
eputs (" => fd="); eputs (itoa (fd)); eputs ("\n"); eputs (" => fd=");
eputs (itoa (fd));
eputs ("\n");
} }
if (!fd) if (!fd)

View file

@ -50,14 +50,19 @@ fread (void *data, size_t size, size_t count, FILE *stream)
if (__mes_debug ()) if (__mes_debug ())
{ {
eputs ("fread fd="); eputs (itoa ((int)stream)); eputs ("fread fd=");
eputs (" bytes="); eputs (itoa (bytes)); eputs ("\n"); eputs (itoa ((int) stream));
eputs (" bytes=");
eputs (itoa (bytes));
eputs ("\n");
static char buf[4096]; static char buf[4096];
if (bytes > 0 && bytes < sizeof (buf)) if (bytes > 0 && bytes < sizeof (buf))
{ {
strncpy (buf, data, bytes); strncpy (buf, data, bytes);
buf[bytes] = 0; buf[bytes] = 0;
eputs ("fread buf="); eputs (buf); eputs ("\n"); eputs ("fread buf=");
eputs (buf);
eputs ("\n");
} }
} }

View file

@ -27,8 +27,11 @@ 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 ()) if (__mes_debug ())
{ {
eputs ("fread fd="); eputs (itoa ((int)stream)); eputs ("fread fd=");
eputs (" =>"); eputs (itoa (pos)); eputs ("\n"); eputs (itoa ((int) stream));
eputs (" =>");
eputs (itoa (pos));
eputs ("\n");
} }
if (pos >= 0) if (pos >= 0)
return 0; return 0;

View file

@ -26,8 +26,11 @@ fwrite (void const *data, size_t size, size_t count, FILE *stream)
{ {
if (__mes_debug () > 1) if (__mes_debug () > 1)
{ {
eputs ("fwrite "); eputs (itoa ((int)stream)); eputs ("fwrite ");
eputs (" "); eputs (itoa (size)); eputs ("\n"); eputs (itoa ((int) stream));
eputs (" ");
eputs (itoa (size));
eputs ("\n");
} }
if (!size || !count) if (!size || !count)
@ -36,7 +39,9 @@ fwrite (void const *data, size_t size, size_t count, FILE *stream)
if (__mes_debug () > 2) if (__mes_debug () > 2)
{ {
eputs (" => "); eputs (itoa (bytes)); eputs ("\n"); eputs (" => ");
eputs (itoa (bytes));
eputs ("\n");
} }
if (bytes > 0) if (bytes > 0)

View file

@ -107,9 +107,7 @@ vfprintf (FILE* f, char const* format, va_list ap)
case 'X': case 'X':
{ {
long d = va_arg (ap, long); long d = va_arg (ap, long);
int base = c == 'o' ? 8 int base = c == 'o' ? 8 : c == 'x' || c == 'X' ? 16 : 10;
: c == 'x' || c == 'X' ? 16
: 10;
char const *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X'); char const *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X');
if (c == 'X') if (c == 'X')
strupr (s); strupr (s);

View file

@ -112,9 +112,7 @@ vsnprintf (char *str, size_t size, char const* format, va_list ap)
case 'X': case 'X':
{ {
long d = va_arg (ap, long); long d = va_arg (ap, long);
int base = c == 'o' ? 8 int base = c == 'o' ? 8 : c == 'x' || c == 'X' ? 16 : 10;
: c == 'x' || c == 'X' ? 16
: 10;
char const *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X'); char const *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X');
if (c == 'X') if (c == 'X')
strupr (s); strupr (s);

View file

@ -62,8 +62,7 @@ alloca (size_t size)
union alloca_header *hp; /* Traverses linked list. */ union alloca_header *hp; /* Traverses linked list. */
for (hp = last_alloca_header; hp != NULL;) for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth) if ((STACK_DIR > 0 && hp->h.deep > depth) || (STACK_DIR < 0 && hp->h.deep < depth))
|| (STACK_DIR < 0 && hp->h.deep < depth))
{ {
union alloca_header *np = hp->h.next; union alloca_header *np = hp->h.next;

View file

@ -24,8 +24,7 @@
typedef char wchar_t[]; typedef char wchar_t[];
size_t size_t
mbstowcs (wchar_t *wstring, char const *string, mbstowcs (wchar_t * wstring, char const *string, size_t size)
size_t size)
{ {
static int stub = 0; static int stub = 0;
if (__mes_debug () && !stub) if (__mes_debug () && !stub)

View file

@ -40,5 +40,5 @@ __argz_count (const char *argz, size_t len)
} }
return 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)

View file

@ -39,4 +39,5 @@ __argz_extract (const char *argz, size_t len, char **argv)
} }
*argv = 0; *argv = 0;
} }
weak_alias (__argz_extract, argz_extract) weak_alias (__argz_extract, argz_extract)

View file

@ -28,8 +28,7 @@
Manual v1.15, but it is with /usr/include/string.h */ Manual v1.15, but it is with /usr/include/string.h */
unsigned char * unsigned char *
_memmem (unsigned char const *haystack, int haystack_len, _memmem (unsigned char const *haystack, int haystack_len, unsigned char const *needle, int needle_len)
unsigned char const *needle, int needle_len)
{ {
unsigned char const *end_haystack = haystack + haystack_len - needle_len + 1; unsigned char const *end_haystack = haystack + haystack_len - needle_len + 1;
unsigned char const *end_needle = needle + needle_len; unsigned char const *end_needle = needle + needle_len;
@ -53,8 +52,7 @@ _memmem (unsigned char const *haystack, int haystack_len,
} }
void * void *
memmem (void const *haystack, int haystack_len, memmem (void const *haystack, int haystack_len, void const *needle, int needle_len)
void const *needle, int needle_len)
{ {
unsigned char const *haystack_byte_c = (unsigned char const *) haystack; unsigned char const *haystack_byte_c = (unsigned char const *) haystack;
unsigned char const *needle_byte_c = (unsigned char const *) needle; unsigned char const *needle_byte_c = (unsigned char const *) needle;

View file

@ -20,8 +20,7 @@
#include <string.h> #include <string.h>
char *sys_errlist[] = char *sys_errlist[] = {
{
"error 00", "error 00",
"error 01", "error 01",
"error 02", "error 02",
@ -71,7 +70,9 @@ strerror (int errnum)
{ {
if (__mes_debug ()) 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) if (errnum > 0 && errnum <= sys_nerr)
return sys_errlist[errnum]; return sys_errlist[errnum];

View file

@ -21,8 +21,7 @@
#include <mes/lib.h> #include <mes/lib.h>
size_t size_t
strftime (char *s, size_t size, char const *template, strftime (char *s, size_t size, char const *template, struct tm const *brokentime)
struct tm const *brokentime)
{ {
static int stub = 0; static int stub = 0;
if (__mes_debug () && !stub) if (__mes_debug () && !stub)

View file

@ -99,7 +99,8 @@ main ()
qsort (list, 5, sizeof (char *), qsort_strcmp); qsort (list, 5, sizeof (char *), qsort_strcmp);
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
oputs (list[i]); oputs ("\n"); oputs (list[i]);
oputs ("\n");
} }
if (strcmp (list[0], ".")) if (strcmp (list[0], "."))

View file

@ -74,27 +74,55 @@ main ()
if (r < 0) if (r < 0)
return 1; return 1;
eputs ("st_dev="); eputs (itoa (sbuf.st_dev)); eputs ("\n"); eputs ("st_dev=");
eputs ("st_ino="); eputs (itoa (sbuf.st_ino)); eputs ("\n"); eputs (itoa (sbuf.st_dev));
eputs ("st_mode="); eputs (itoa (sbuf.st_mode)); eputs ("\n"); eputs ("\n");
eputs ("st_nlink="); eputs (itoa (sbuf.st_nlink)); eputs ("\n"); eputs ("st_ino=");
eputs ("st_uid="); eputs (itoa (sbuf.st_uid)); eputs ("\n"); eputs (itoa (sbuf.st_ino));
eputs ("st_gid="); eputs (itoa (sbuf.st_gid)); eputs ("\n"); eputs ("\n");
eputs ("st_rdev="); eputs (itoa (sbuf.st_rdev)); eputs ("\n"); eputs ("st_mode=");
eputs ("st_size="); eputs (itoa (sbuf.st_size)); eputs ("\n"); 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_blksize=");
eputs ("st_blocks="); eputs (itoa (sbuf.st_blocks)); eputs ("\n"); 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_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_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 ("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; return 0;
} }

View file

@ -28,7 +28,9 @@ main ()
oputs ("\n"); oputs ("\n");
oputs ("t: itoa (33) == \"33\"\n"); oputs ("t: itoa (33) == \"33\"\n");
oputs ("=>"); oputs (itoa (33)); oputs ("\n"); oputs ("=>");
oputs (itoa (33));
oputs ("\n");
if (strcmp (itoa (33), "33")) if (strcmp (itoa (33), "33"))
return 1; return 1;

View file

@ -32,7 +32,9 @@ handler (int signum)
#if __MESC__ && __x86_64__ #if __MESC__ && __x86_64__
asm ("mov____%rdi,0x8(%rbp) !0x10"); // FIXME: AMDCC asm ("mov____%rdi,0x8(%rbp) !0x10"); // FIXME: AMDCC
#endif #endif
eputs ("handle:"); eputs (itoa (signum)); eputs ("\n"); eputs ("handle:");
eputs (itoa (signum));
eputs ("\n");
if (signum != SIGALRM) if (signum != SIGALRM)
exit (66); exit (66);
g_alarm_handled_p = 1; g_alarm_handled_p = 1;
@ -44,7 +46,9 @@ handler (int signum)
int int
main (void) 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); signal (SIGALRM, handler);
kill (getpid (), SIGALRM); kill (getpid (), SIGALRM);
if (!g_alarm_handled_p) if (!g_alarm_handled_p)

View file

@ -54,7 +54,9 @@ main ()
return 4; return 4;
sprintf (buf, "%u", -1); sprintf (buf, "%u", -1);
eputs ("buf="); eputs (buf); eputs ("\n"); eputs ("buf=");
eputs (buf);
eputs ("\n");
#if __i386__ #if __i386__
if (strcmp (buf, "4294967295")) if (strcmp (buf, "4294967295"))
@ -65,17 +67,20 @@ main ()
#endif #endif
sprintf (buf, ">>%o<<\n", 12); sprintf (buf, ">>%o<<\n", 12);
eputs ("buf="); eputs (buf); eputs ("buf=");
eputs (buf);
if (strcmp (buf, ">>14<<\n")) if (strcmp (buf, ">>14<<\n"))
return 7; return 7;
sprintf (buf, ">>%x<<\n", 12); sprintf (buf, ">>%x<<\n", 12);
eputs ("buf="); eputs (buf); eputs ("buf=");
eputs (buf);
if (strcmp (buf, ">>c<<\n")) if (strcmp (buf, ">>c<<\n"))
return 8; return 8;
sprintf (buf, ">>%X<<\n", 12); sprintf (buf, ">>%X<<\n", 12);
eputs ("buf="); eputs (buf); eputs ("buf=");
eputs (buf);
if (strcmp (buf, ">>C<<\n")) if (strcmp (buf, ">>C<<\n"))
return 9; return 9;

View file

@ -53,22 +53,26 @@ main ()
return 3; return 3;
sprintf (buf, ">%3d<", 11); sprintf (buf, ">%3d<", 11);
eputs (buf); eputs ("\n"); eputs (buf);
eputs ("\n");
if (strcmp (buf, "> 11<")) if (strcmp (buf, "> 11<"))
return 4; return 4;
sprintf (buf, ">%03d<", 22); sprintf (buf, ">%03d<", 22);
eputs (buf); eputs ("\n"); eputs (buf);
eputs ("\n");
if (strcmp (buf, ">022<")) if (strcmp (buf, ">022<"))
return 5; return 5;
sprintf (buf, ">%-10d<", 33); sprintf (buf, ">%-10d<", 33);
eputs (buf); eputs ("\n"); eputs (buf);
eputs ("\n");
if (strcmp (buf, ">33 <")) if (strcmp (buf, ">33 <"))
return 6; return 6;
sprintf (buf, ">%0d<", 44); sprintf (buf, ">%0d<", 44);
eputs (buf); eputs ("\n"); eputs (buf);
eputs ("\n");
if (strcmp (buf, ">44<")) if (strcmp (buf, ">44<"))
return 7; return 7;
@ -80,12 +84,16 @@ main ()
printf (">>%-*s<<\n", 10, "baz"); printf (">>%-*s<<\n", 10, "baz");
sprintf (buf, "%ld", 42); sprintf (buf, "%ld", 42);
eputs ("buf="); eputs (buf); eputs ("\n"); eputs ("buf=");
eputs (buf);
eputs ("\n");
if (strcmp (buf, "42")) if (strcmp (buf, "42"))
return 8; return 8;
sprintf (buf, "%u", -1); sprintf (buf, "%u", -1);
eputs ("buf="); eputs (buf); eputs ("\n"); eputs ("buf=");
eputs (buf);
eputs ("\n");
#if __i386__ #if __i386__
if (strcmp (buf, "4294967295")) if (strcmp (buf, "4294967295"))
@ -96,52 +104,62 @@ main ()
#endif #endif
sprintf (buf, ">>%.5s<<\n", "hello, world"); sprintf (buf, ">>%.5s<<\n", "hello, world");
eputs ("buf="); eputs (buf); eputs ("buf=");
eputs (buf);
if (strcmp (buf, ">>hello<<\n")) if (strcmp (buf, ">>hello<<\n"))
return 10; return 10;
sprintf (buf, ">>%.*s<<\n", 5, "hello, world"); sprintf (buf, ">>%.*s<<\n", 5, "hello, world");
eputs ("buf="); eputs (buf); eputs ("buf=");
eputs (buf);
if (strcmp (buf, ">>hello<<\n")) if (strcmp (buf, ">>hello<<\n"))
return 11; return 11;
sprintf (buf, ">>%.*s<<\n", 20, "hello, world"); sprintf (buf, ">>%.*s<<\n", 20, "hello, world");
eputs ("buf="); eputs (buf); eputs ("buf=");
eputs (buf);
if (strcmp (buf, ">>hello, world<<\n")) if (strcmp (buf, ">>hello, world<<\n"))
return 12; return 12;
sprintf (buf, ">>%.*s<<\n", 10, "foo"); sprintf (buf, ">>%.*s<<\n", 10, "foo");
eputs ("buf="); eputs (buf); eputs ("buf=");
eputs (buf);
if (strcmp (buf, ">>foo<<\n")) if (strcmp (buf, ">>foo<<\n"))
return 13; return 13;
sprintf (buf, ">>%*s<<\n", 10, "bar"); sprintf (buf, ">>%*s<<\n", 10, "bar");
eputs ("buf="); eputs (buf); eputs ("buf=");
eputs (buf);
if (strcmp (buf, ">> bar<<\n")) if (strcmp (buf, ">> bar<<\n"))
return 14; return 14;
sprintf (buf, ">>%-*s<<\n", 10, "baz"); sprintf (buf, ">>%-*s<<\n", 10, "baz");
eputs ("buf="); eputs (buf); eputs ("buf=");
eputs (buf);
if (strcmp (buf, ">>baz <<\n")) if (strcmp (buf, ">>baz <<\n"))
return 15; return 15;
sprintf (buf, ">>%ld<<\n", 12); sprintf (buf, ">>%ld<<\n", 12);
eputs ("buf="); eputs (buf); eputs ("buf=");
eputs (buf);
if (strcmp (buf, ">>12<<\n")) if (strcmp (buf, ">>12<<\n"))
return 16; return 16;
sprintf (buf, ">>%o<<\n", 12); sprintf (buf, ">>%o<<\n", 12);
eputs ("buf="); eputs (buf); eputs ("buf=");
eputs (buf);
if (strcmp (buf, ">>14<<\n")) if (strcmp (buf, ">>14<<\n"))
return 17; return 17;
sprintf (buf, ">>%x<<\n", 12); sprintf (buf, ">>%x<<\n", 12);
eputs ("buf="); eputs (buf); eputs ("buf=");
eputs (buf);
if (strcmp (buf, ">>c<<\n")) if (strcmp (buf, ">>c<<\n"))
return 18; return 18;
sprintf (buf, ">>%X<<\n", 12); sprintf (buf, ">>%X<<\n", 12);
eputs ("buf="); eputs (buf); eputs ("buf=");
eputs (buf);
if (strcmp (buf, ">>C<<\n")) if (strcmp (buf, ">>C<<\n"))
return 19; return 19;
@ -153,7 +171,9 @@ main ()
#endif #endif
sprintf (buf, "foo%nbar\n", &n); sprintf (buf, "foo%nbar\n", &n);
eputs ("buf="); eputs (buf); eputs ("\n"); eputs ("buf=");
eputs (buf);
eputs ("\n");
if (strcmp (buf, "foobar\n")) if (strcmp (buf, "foobar\n"))
return 21; return 21;
if (n != 3) if (n != 3)
@ -164,7 +184,9 @@ main ()
#endif #endif
sprintf (buf, "%12.8d\n", 12345); sprintf (buf, "%12.8d\n", 12345);
eputs ("buf="); eputs (buf); eputs ("\n"); eputs ("buf=");
eputs (buf);
eputs ("\n");
if (strcmp (buf, " 00012345\n")) if (strcmp (buf, " 00012345\n"))
return 23; return 23;

View file

@ -25,7 +25,8 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
int main() int
main ()
{ {
FILE *test = fopen ("tmp", "a+"); FILE *test = fopen ("tmp", "a+");
FILE *hold = fopen ("tmp", "r"); FILE *hold = fopen ("tmp", "r");
@ -42,9 +43,11 @@ int main()
fflush (test); fflush (test);
fputc ('a', test); fputc ('a', test);
} }
if(b == EOF) exit(EXIT_SUCCESS); if (b == EOF)
exit (EXIT_SUCCESS);
i = i + 1; i = i + 1;
}while (a == b); }
while (a == b);
fprintf (stderr, "OOOPS you were not supposed to get here\n"); fprintf (stderr, "OOOPS you were not supposed to get here\n");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }

View file

@ -53,7 +53,9 @@ main ()
char buf[80]; char buf[80];
memset (buf, 0, sizeof (buf)); memset (buf, 0, sizeof (buf));
fread (buf, strlen (line), 1, t); fread (buf, strlen (line), 1, t);
eputs ("buf="); eputs (buf); eputs ("\n"); eputs ("buf=");
eputs (buf);
eputs ("\n");
if (strcmp (buf, line)) if (strcmp (buf, line))
return 2; return 2;
@ -62,7 +64,9 @@ main ()
fseek (t, 0, SEEK_SET); fseek (t, 0, SEEK_SET);
memset (buf, 0, sizeof (buf)); memset (buf, 0, sizeof (buf));
fread (buf, strlen (line), 1, t); fread (buf, strlen (line), 1, t);
eputs ("buf="); eputs (buf); eputs ("\n"); eputs ("buf=");
eputs (buf);
eputs ("\n");
if (strcmp (buf, line)) if (strcmp (buf, line))
return 3; return 3;
@ -76,7 +80,9 @@ main ()
fseek (t, 0, SEEK_SET); fseek (t, 0, SEEK_SET);
memset (buf, 0, sizeof (buf)); memset (buf, 0, sizeof (buf));
fread (buf, strlen (end), 1, t); fread (buf, strlen (end), 1, t);
eputs ("buf="); eputs (buf); eputs ("\n"); eputs ("buf=");
eputs (buf);
eputs ("\n");
if (strcmp (buf, end)) if (strcmp (buf, end))
return 5; return 5;
@ -98,7 +104,9 @@ main ()
fseek (t, 0, SEEK_SET); fseek (t, 0, SEEK_SET);
memset (buf, 0, sizeof (buf)); memset (buf, 0, sizeof (buf));
fread (buf, strlen (line), 1, t); fread (buf, strlen (line), 1, t);
eputs ("buf="); eputs (buf); eputs ("\n"); eputs ("buf=");
eputs (buf);
eputs ("\n");
if (strcmp (buf, line)) if (strcmp (buf, line))
return 8; return 8;
@ -106,7 +114,9 @@ main ()
fseek (t, 0, SEEK_SET); fseek (t, 0, SEEK_SET);
fread (buf, strlen (line), 1, t); fread (buf, strlen (line), 1, t);
eputs ("buf="); eputs (buf); eputs ("\n"); eputs ("buf=");
eputs (buf);
eputs ("\n");
if (strcmp (buf, line)) if (strcmp (buf, line))
return 9; return 9;

View file

@ -59,7 +59,9 @@ main ()
char buf[200]; char buf[200];
fflush (n); fflush (n);
fread (buf, strlen (header_plus_data), 1, test); 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)) if (strcmp (buf, header_plus_data))
return 1; return 1;

View file

@ -43,14 +43,17 @@ main ()
return 4; return 4;
pos = ftell (f); pos = ftell (f);
eputs ("size="); eputs (itoa (pos)); eputs ("\n"); eputs ("size=");
eputs (itoa (pos));
eputs ("\n");
if (pos != 35147) if (pos != 35147)
return 5; return 5;
r = fseek (f, 0, SEEK_SET); r = fseek (f, 0, SEEK_SET);
char buf[4096]; char buf[4096];
fgets (buf, 200, f); fgets (buf, 200, f);
eputs ("buf:"); eputs (buf); eputs ("buf:");
eputs (buf);
if (strcmp (buf, " GNU GENERAL PUBLIC LICENSE\n")) if (strcmp (buf, " GNU GENERAL PUBLIC LICENSE\n"))
return 6; return 6;

View file

@ -29,15 +29,19 @@ main ()
{ {
char *p = "42foo\n"; char *p = "42foo\n";
int n = abtol (&p, 0); int n = abtol (&p, 0);
if (n != 42) return 1; if (n != 42)
return 1;
eputs (p); eputs (p);
if (strcmp (p, "foo\n")) return 2; if (strcmp (p, "foo\n"))
return 2;
p = "2azar\n"; p = "2azar\n";
n = strtoull (p, (char **) &p, 16); n = strtoull (p, (char **) &p, 16);
if (n != 42) return 3; if (n != 42)
return 3;
eputs (p); eputs (p);
if (strcmp (p, "zar\n")) return 4; if (strcmp (p, "zar\n"))
return 4;
return 0; return 0;
} }

View file

@ -35,7 +35,8 @@ main ()
qsort (list, 2, sizeof (char *), qsort_strcmp); qsort (list, 2, sizeof (char *), qsort_strcmp);
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
oputs (list[i]); oputs ("\n"); oputs (list[i]);
oputs ("\n");
} }
return 0; return 0;

View file

@ -25,8 +25,13 @@
int int
compare_int (void *a, void *b) compare_int (void *a, void *b)
{ {
eputs ("compare: "); eputs (itoa (*(int*)a)); eputs (" <? "); eputs (itoa (*(int*)b)); eputs ("compare: ");
eputs (" => "); eputs (itoa (*(int*)a - *(int*)b)); eputs ("\n"); eputs (itoa (*(int *) a));
eputs (" <? ");
eputs (itoa (*(int *) b));
eputs (" => ");
eputs (itoa (*(int *) a - *(int *) b));
eputs ("\n");
return *(int *) a - *(int *) b; return *(int *) a - *(int *) b;
} }
@ -37,9 +42,14 @@ main ()
qsort (lst, 6, sizeof (int), compare_int); qsort (lst, 6, sizeof (int), compare_int);
for (int i = 0; i < 6; i++) 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[0] != -1)
if (lst[5] != 5) return 2; return 1;
if (lst[5] != 5)
return 2;
return 0; return 0;
} }

View file

@ -42,13 +42,17 @@ main ()
char *p = "16"; char *p = "16";
int n = strtol (p, (char **) &p, 0); int n = strtol (p, (char **) &p, 0);
eputs ("p="); eputs (p); eputs ("\n"); eputs ("p=");
eputs (p);
eputs ("\n");
if (*p != 0) if (*p != 0)
return 5; return 5;
p = "0x12"; p = "0x12";
n = strtol (p, (char **) &p, 0); n = strtol (p, (char **) &p, 0);
eputs ("p="); eputs (p); eputs ("\n"); eputs ("p=");
eputs (p);
eputs ("\n");
if (*p != 0) if (*p != 0)
return 5; return 5;

View file

@ -37,12 +37,14 @@ main ()
return 2; return 2;
oputs ("t: if (!strcmp (p, \"t.c\\n\"))\n"); oputs ("t: if (!strcmp (p, \"t.c\\n\"))\n");
if (!strcmp (p, "mes")) goto ok1; if (!strcmp (p, "mes"))
goto ok1;
return 3; return 3;
ok1: ok1:
oputs ("t: if (strcmp (p, \"foo\"))\n"); oputs ("t: if (strcmp (p, \"foo\"))\n");
if (strcmp (p, "foo")) goto ok2; if (strcmp (p, "foo"))
goto ok2;
return 4; return 4;
ok2: ok2:

View file

@ -28,7 +28,9 @@ int
main () main ()
{ {
int n = snprintf (0, 0, "%s", "0123456"); int n = snprintf (0, 0, "%s", "0123456");
eputs ("***n="); eputs (itoa (n)); eputs ("\n"); eputs ("***n=");
eputs (itoa (n));
eputs ("\n");
exit (n != 7); exit (n != 7);
/* if (n) */ /* if (n) */

View file

@ -27,12 +27,14 @@ main ()
strcpy (buf, "foo"); strcpy (buf, "foo");
strcat (buf, " bar"); strcat (buf, " bar");
eputs (buf); eputs ("\n"); eputs (buf);
eputs ("\n");
if (strcmp (buf, "foo bar")) if (strcmp (buf, "foo bar"))
return 1; return 1;
strncat (buf, " bazzzz", 4); strncat (buf, " bazzzz", 4);
eputs (buf); eputs ("\n"); eputs (buf);
eputs ("\n");
if (strcmp (buf, "foo bar baz")) if (strcmp (buf, "foo bar baz"))
return 2; return 2;

View file

@ -43,15 +43,19 @@ SCM r1 = 0; // param 1
SCM r2 = 0; // save 2+load/dump SCM r2 = 0; // save 2+load/dump
SCM r3 = 0; // continuation 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; enum type_t type;
SCM car; SCM car;
SCM cdr; SCM cdr;
}; };
struct function { struct function
{
int (*function) (void); int (*function) (void);
int arity; int arity;
char *name; char *name;
@ -103,24 +107,28 @@ int g_function = 0;
SCM make_cell_ (SCM type, SCM car, SCM cdr); SCM make_cell_ (SCM type, SCM car, SCM cdr);
struct function fun_make_cell_ = { &make_cell_, 3, "core:make-cell" }; struct function fun_make_cell_ = { &make_cell_, 3, "core:make-cell" };
struct scm scm_make_cell_ = { TFUNCTION, 0, 0 }; struct scm scm_make_cell_ = { TFUNCTION, 0, 0 };
//, "core:make-cell", 0}; //, "core:make-cell", 0};
SCM cell_make_cell_; SCM cell_make_cell_;
SCM cons (SCM x, SCM y); SCM cons (SCM x, SCM y);
struct function fun_cons = { &cons, 2, "cons" }; struct function fun_cons = { &cons, 2, "cons" };
struct scm scm_cons = { TFUNCTION, 0, 0 }; struct scm scm_cons = { TFUNCTION, 0, 0 };
// "cons", 0}; // "cons", 0};
SCM cell_cons; SCM cell_cons;
SCM car (SCM x); SCM car (SCM x);
struct function fun_car = { &car, 1, "car" }; struct function fun_car = { &car, 1, "car" };
struct scm scm_car = { TFUNCTION, 0, 0 }; struct scm scm_car = { TFUNCTION, 0, 0 };
// "car", 0}; // "car", 0};
SCM cell_car; SCM cell_car;
SCM cdr (SCM x); SCM cdr (SCM x);
struct function fun_cdr = { &cdr, 1, "cdr" }; struct function fun_cdr = { &cdr, 1, "cdr" };
struct scm scm_cdr = { TFUNCTION, 0, 0 }; struct scm scm_cdr = { TFUNCTION, 0, 0 };
// "cdr", 0}; // "cdr", 0};
SCM cell_cdr; SCM cell_cdr;
@ -167,15 +175,22 @@ make_cell_ (SCM type, SCM car, SCM cdr)
SCM x = alloc (1); SCM x = alloc (1);
assert (TYPE (type) == TNUMBER); assert (TYPE (type) == TNUMBER);
TYPE (x) = VALUE (type); TYPE (x) = VALUE (type);
if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER) { if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER)
if (car) CAR (x) = CAR (car); {
if (cdr) CDR(x) = CDR(cdr); if (car)
CAR (x) = CAR (car);
if (cdr)
CDR (x) = CDR (cdr);
} }
else if (VALUE (type) == TFUNCTION) { else if (VALUE (type) == TFUNCTION)
if (car) CAR (x) = car; {
if (cdr) CDR(x) = CDR(cdr); if (car)
CAR (x) = car;
if (cdr)
CDR (x) = CDR (cdr);
} }
else { else
{
CAR (x) = car; CAR (x) = car;
CDR (x) = cdr; CDR (x) = cdr;
} }
@ -226,7 +241,8 @@ gc_push_frame ()
SCM SCM
append2 (SCM x, SCM y) append2 (SCM x, SCM y)
{ {
if (x == cell_nil) return y; if (x == cell_nil)
return y;
assert (TYPE (x) == TPAIR); assert (TYPE (x) == TPAIR);
return cons (car (x), append2 (cdr (x), y)); return cons (car (x), append2 (cdr (x), y));
} }
@ -238,14 +254,14 @@ pairlis (SCM x, SCM y, SCM a)
return a; return a;
if (TYPE (x) != TPAIR) if (TYPE (x) != TPAIR)
return cons (cons (x, y), a); return cons (cons (x, y), a);
return cons (cons (car (x), car (y)), return cons (cons (car (x), car (y)), pairlis (cdr (x), cdr (y), a));
pairlis (cdr (x), cdr (y), a));
} }
SCM SCM
assq (SCM x, SCM a) 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; return a != cell_nil ? car (a) : cell_f;
} }
@ -263,10 +279,29 @@ push_cc (SCM p1, SCM p2, SCM a, SCM c) ///((internal))
return cell_unspecified; return cell_unspecified;
} }
SCM caar (SCM x) {return car (car (x));} SCM
SCM cadr (SCM x) {return car (cdr (x));} caar (SCM x)
SCM cdar (SCM x) {return cdr (car (x));} {
SCM cddr (SCM x) {return cdr (cdr (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__ #if __GNUC__
//FIXME //FIXME
@ -280,8 +315,14 @@ eval_apply ()
eval_apply: eval_apply:
switch (r3) switch (r3)
{ {
case cell_vm_apply: {goto apply;} case cell_vm_apply:
case cell_unspecified: {return r1;} {
goto apply;
}
case cell_unspecified:
{
return r1;
}
} }
SCM x = cell_nil; SCM x = cell_nil;
@ -290,7 +331,8 @@ eval_apply ()
apply: apply:
switch (TYPE (car (r1))) switch (TYPE (car (r1)))
{ {
case TFUNCTION: { case TFUNCTION:
{
puts ("apply.function\n"); puts ("apply.function\n");
r1 = call (car (r1), cdr (r1)); r1 = call (car (r1), cdr (r1));
goto vm_return; goto vm_return;
@ -307,19 +349,33 @@ SCM
call (SCM fn, SCM x) call (SCM fn, SCM x)
{ {
puts ("call\n"); puts ("call\n");
if ((FUNCTION (fn).arity > 0 || FUNCTION (fn).arity == -1) if ((FUNCTION (fn).arity > 0 || FUNCTION (fn).arity == -1) && x != cell_nil && TYPE (CAR (x)) == TVALUES)
&& x != cell_nil && TYPE (CAR (x)) == TVALUES)
x = cons (CADAR (x), CDR (x)); x = cons (CADAR (x), CDR (x));
if ((FUNCTION (fn).arity > 1 || FUNCTION (fn).arity == -1) if ((FUNCTION (fn).arity > 1 || FUNCTION (fn).arity == -1)
&& x != cell_nil && TYPE (CDR (x)) == TPAIR && TYPE (CADR (x)) == TVALUES) && x != cell_nil && TYPE (CDR (x)) == TPAIR && TYPE (CADR (x)) == TVALUES)
x = cons (CAR (x), cons (CDADAR (x), CDR (x))); x = cons (CAR (x), cons (CDADAR (x), CDR (x)));
switch (FUNCTION (fn).arity) switch (FUNCTION (fn).arity)
{ {
case 0: {return (FUNCTION (fn).function) ();} case 0:
case 1: {return ((SCM(*)(SCM))(FUNCTION (fn).function)) (car (x));} {
case 2: {return ((SCM(*)(SCM,SCM))(FUNCTION (fn).function)) (car (x), cadr (x));} return (FUNCTION (fn).function) ();
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 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; return cell_unspecified;
} }
@ -655,7 +711,8 @@ display_ (SCM x)
//puts ("<pair>\n"); //puts ("<pair>\n");
//if (cont != cell_f) puts "("); //if (cont != cell_f) puts "(");
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 (CDR (x) && CDR (x) != cell_nil)
{ {
#if __GNUC__ #if __GNUC__
@ -678,9 +735,21 @@ display_ (SCM x)
{ {
switch (x) switch (x)
{ {
case 1: {puts ("()"); break;} case 1:
case 2: {puts ("#f"); break;} {
case 3: {puts ("#t"); break;} puts ("()");
break;
}
case 2:
{
puts ("#f");
break;
}
case 3:
{
puts ("#t");
break;
}
default: default:
{ {
#if __GNUC__ #if __GNUC__
@ -698,16 +767,56 @@ display_ (SCM x)
{ {
switch (x) switch (x)
{ {
case 11: {puts (" . "); break;} case 11:
case 12: {puts ("lambda"); break;} {
case 13: {puts ("begin"); break;} puts (" . ");
case 14: {puts ("if"); break;} break;
case 15: {puts ("quote"); break;} }
case 37: {puts ("car"); break;} case 12:
case 38: {puts ("cdr"); break;} {
case 39: {puts ("null?"); break;} puts ("lambda");
case 40: {puts ("eq?"); break;} break;
case 41: {puts ("cons"); 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: default:
{ {
#if __GNUC__ #if __GNUC__
@ -747,7 +856,11 @@ simple_bload_env (SCM a) ///((internal))
puts (mo); puts (mo);
puts ("\n"); puts ("\n");
__stdin = open (mo, 0); __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; int c;
@ -775,14 +888,16 @@ simple_bload_env (SCM a) ///((internal))
g_free = (p - (char *) g_cells) / sizeof (struct scm); g_free = (p - (char *) g_cells) / sizeof (struct scm);
if (g_free != 15) exit (33); if (g_free != 15)
exit (33);
g_symbols = 1; g_symbols = 1;
__stdin = STDIN; __stdin = STDIN;
r0 = mes_builtins (r0); r0 = mes_builtins (r0);
if (g_free != 19) exit (34); if (g_free != 19)
exit (34);
puts ("cells read: "); puts ("cells read: ");
puts (itoa (g_free)); puts (itoa (g_free));
@ -820,11 +935,20 @@ int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
puts ("Hello cons-mes!\n"); 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 __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 #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 #endif
__stdin = STDIN; __stdin = STDIN;
@ -869,4 +993,3 @@ main (int argc, char *argv[])
eputs ("\n"); eputs ("\n");
return 0; return 0;
} }

View file

@ -29,7 +29,8 @@ main (int argc, char *argv[])
int c = getchar (); int c = getchar ();
if (c != 'm') if (c != 'm')
return 1; return 1;
while (c != EOF) { while (c != EOF)
{
putchar (c); putchar (c);
c = getchar (); c = getchar ();
} }

View file

@ -24,7 +24,9 @@ int
main () main ()
{ {
int c = 0; int c = 0;
{int c = 3;} {
int c = 3;
}
if (c) if (c)
return 1; return 1;

View file

@ -83,7 +83,8 @@ main (int c)
oputs ("t: if (0); return 1; else;\n"); oputs ("t: if (0); return 1; else;\n");
if (0) if (0)
return 12; else return 12;
else
goto ok1; goto ok1;
ok1: ok1:

View file

@ -20,7 +20,9 @@
#include <mes/lib-mini.h> #include <mes/lib-mini.h>
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 int
add (int a, int b) add (int a, int b)

View file

@ -25,7 +25,8 @@ main ()
{ {
int r; int r;
int i = 2; int i = 2;
switch (i) { switch (i)
{
// case 0: // case 0:
// r = 0; // r = 0;
// break; // break;

View file

@ -25,7 +25,8 @@ main ()
{ {
int r; int r;
int i = 2; int i = 2;
switch (i) { switch (i)
{
// case 0: // case 0:
// r = 0; // r = 0;
// break; // break;

View file

@ -20,7 +20,9 @@
#include <mes/lib-mini.h> #include <mes/lib-mini.h>
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 int
swits (int c) swits (int c)
@ -96,7 +98,8 @@ default_first (int c)
there: there:
case 0: case 0:
; ;
{} {
}
return 0; return 0;
} }
return -1; return -1;

View file

@ -25,7 +25,9 @@ main ()
{ {
int **p = 1; int **p = 1;
int **q = -1; int **q = -1;
oputs ("p - q"); oputs (itoa (p - q)); oputs ("\n"); oputs ("p - q");
oputs (itoa (p - q));
oputs ("\n");
return 0; return 0;
} }

View file

@ -26,7 +26,9 @@
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
oputs ("argc="); oputs (itoa (argc)); oputs ("\n"); oputs ("argc=");
oputs (itoa (argc));
oputs ("\n");
if (argc != 1) if (argc != 1)
return 1; return 1;

View file

@ -28,7 +28,9 @@ main (int argc, char *argv[])
{ {
oputs ("\n"); oputs ("\n");
oputs ("t: argv[0] == \"scaffold/test....\"\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)) if (strncmp (argv[0], "scaffold/test", 5))
return 1; return 1;

View file

@ -18,22 +18,16 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
char g_hello[] = char g_hello[] = "hello\n" "world\n";
"hello\n"
"world\n"
;
char *g_hello2 = char *g_hello2 = "hello\n" "world\n";
"hello\n"
"world\n"
;
char g_hello3[] = char g_hello3[] = {
{
'h', 'e', 'l', 'l', 'o', '\n', 'h', 'e', 'l', 'l', 'o', '\n',
'w', 'o', 'r', 'l', 'd', '\n', 'w', 'o', 'r', 'l', 'd', '\n',
'\0', '\0',
} }
; ;
int g_hello_int[] = { 0, 1, 2, 3, 4, 5 }; int g_hello_int[] = { 0, 1, 2, 3, 4, 5 };

View file

@ -35,11 +35,17 @@ getenv (char const* s)
eputs ("getenv\n"); eputs ("getenv\n");
char **p = environ; char **p = environ;
int length = strlen (s); int length = strlen (s);
eputs ("getenv length="); eputs (itoa (length)); eputs ("\n"); eputs ("getenv length=");
eputs (itoa (length));
eputs ("\n");
while (*p) while (*p)
{ {
eputs ("*p="); eputs (*p); eputs ("\n");; eputs ("*p=");
eputs (" p="); eputs (itoa ((long)p)); eputs ("\n"); eputs (*p);
eputs ("\n");;
eputs (" p=");
eputs (itoa ((long) p));
eputs ("\n");
if (!strncmp (s, *p, length) && *(*p + length) == '=') if (!strncmp (s, *p, length) && *(*p + length) == '=')
return (*p + length + 1); return (*p + length + 1);
p++; p++;

View file

@ -19,18 +19,15 @@
*/ */
#include <string.h> #include <string.h>
int one_two_three[3] = int one_two_three[3] = {
{
1, 2, 3 1, 2, 3
}; };
char *foo_bar_baz[3] = char *foo_bar_baz[3] = {
{
"foo", "bar", "baz" "foo", "bar", "baz"
}; };
char foo_bar_baz_haha[3][4] = char foo_bar_baz_haha[3][4] = {
{
"foo", "bar", "baz" "foo", "bar", "baz"
}; };
@ -38,18 +35,25 @@ char *foo = "foo";
char *bar = "bar"; char *bar = "bar";
char *baz = "baz"; char *baz = "baz";
char *foo_bar_baz_mwhuhahaha[3] = char *foo_bar_baz_mwhuhahaha[3] = {
{
&foo, &bar, &baz &foo, &bar, &baz
}; };
int int
main () main ()
{ {
puts ("one:"); puts (itoa (one_two_three[0])); puts ("\n"); puts ("one:");
puts ("foo:"); puts (foo_bar_baz[1]); puts ("\n"); puts (itoa (one_two_three[0]));
puts ("bar:"); puts (foo_bar_baz_haha[2]); puts ("\n"); 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]; 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"); return strcmp (foo_bar_baz[2], "baz");
} }

View file

@ -36,7 +36,8 @@ inc (int i)
return i + 1; return i + 1;
} }
struct scm { struct scm
{
int type; int type;
int car; int car;
int cdr; int cdr;
@ -51,8 +52,20 @@ struct scm *g_cells = (struct scm*)g_arena;
#endif #endif
char *g_chars = g_arena; char *g_chars = g_arena;
int foo () {oputs ("t: foo\n"); return 0;}; int
int bar (int i) {oputs ("t: bar\n"); return 0;}; foo ()
{
oputs ("t: foo\n");
return 0;
};
int
bar (int i)
{
oputs ("t: bar\n");
return 0;
};
struct function struct function
{ {
int (*function) (void); int (*function) (void);
@ -70,7 +83,9 @@ void *functions[2];
struct function g_functions[2]; struct function g_functions[2];
int g_function = 0; 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; typedef int SCM;
int g_free = 3; int g_free = 3;
@ -86,6 +101,7 @@ int ARENA_SIZE = 200;
#define CAAR(x) CAR (CAR (x)) #define CAAR(x) CAR (CAR (x))
struct scm scm_fun = { TFUNCTION, 0, 0 }; struct scm scm_fun = { TFUNCTION, 0, 0 };
SCM cell_fun; SCM cell_fun;

View file

@ -28,6 +28,7 @@ struct function
char *name; char *name;
}; };
struct function g_fun = { &exit, 1, "fun" }; struct function g_fun = { &exit, 1, "fun" };
int functions[2]; int functions[2];
int g_function = 0; int g_function = 0;

View file

@ -28,6 +28,7 @@ struct scm
}; };
struct scm a = { -1, 0, -1 }; struct scm a = { -1, 0, -1 };
struct scm *p = &a; struct scm *p = &a;
int int

View file

@ -24,7 +24,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
struct scm { struct scm
{
int type; int type;
int car; int car;
int cdr; int cdr;
@ -35,9 +36,22 @@ 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; char *g_chars = g_arena;
int foo () {oputs ("t: foo\n"); return 0;}; int
int bar (int i) {oputs ("t: bar\n"); return 0;}; foo ()
struct function { {
oputs ("t: foo\n");
return 0;
};
int
bar (int i)
{
oputs ("t: bar\n");
return 0;
};
struct function
{
int (*function) (void); int (*function) (void);
int arity; int arity;
char *name; char *name;
@ -52,7 +66,9 @@ int functions[2];
struct function g_functions[2]; struct function g_functions[2];
int g_function = 0; 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; typedef int SCM;
int g_free = 3; int g_free = 3;
@ -68,6 +84,7 @@ int ARENA_SIZE = 200;
#define CAAR(x) CAR (CAR (x)) #define CAAR(x) CAR (CAR (x))
struct scm scm_fun = { TFUNCTION, 0, 0 }; struct scm scm_fun = { TFUNCTION, 0, 0 };
SCM cell_fun; SCM cell_fun;
SCM SCM
@ -85,15 +102,22 @@ make_cell (SCM type, SCM car, SCM cdr)
oputs ("030\n"); oputs ("030\n");
SCM x = alloc (1); SCM x = alloc (1);
TYPE (x) = VALUE (type); TYPE (x) = VALUE (type);
if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER) { if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER)
if (car) CAR (x) = CAR (car); {
if (cdr) CDR(x) = CDR(cdr); if (car)
CAR (x) = CAR (car);
if (cdr)
CDR (x) = CDR (cdr);
} }
else if (VALUE (type) == TFUNCTION) { else if (VALUE (type) == TFUNCTION)
if (car) CAR (x) = car; {
if (cdr) CDR(x) = CDR(cdr); if (car)
CAR (x) = car;
if (cdr)
CDR (x) = CDR (cdr);
} }
else { else
{
CAR (x) = car; CAR (x) = car;
CDR (x) = cdr; CDR (x) = cdr;
} }

View file

@ -46,12 +46,14 @@ calloc (size_t nmemb, size_t size)
} }
/* {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'} */ /* {'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 * char *
little_endian (unsigned value, char *c, int number_of_bytes) 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)
{ {
@ -89,15 +91,21 @@ main ()
char *s; char *s;
s = calloc (10, sizeof (char)); 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")) if (strcmp (s, "02"))
return 1; 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")) if (strcmp (s, "0800"))
return 2; 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")) if (strcmp (s, "10000000"))
return 3; return 3;

View file

@ -37,7 +37,9 @@ stdarg1 (long* one, ...)
#endif #endif
c = va_arg (ap, char); c = va_arg (ap, char);
r = c; r = c;
eputs ("c:"); eputs (itoa (c)); eputs ("\n"); eputs ("c:");
eputs (itoa (c));
eputs ("\n");
va_end (ap); va_end (ap);
return r; return r;
@ -59,7 +61,9 @@ stdarg2 (long* one, long* two, ...)
#endif #endif
c = va_arg (ap, char); c = va_arg (ap, char);
r = c; r = c;
eputs ("c:"); eputs (itoa (c)); eputs ("\n"); eputs ("c:");
eputs (itoa (c));
eputs ("\n");
va_end (ap); va_end (ap);
return r; return r;
@ -81,7 +85,9 @@ stdarg3 (long *one, long* two, long* three, ...)
#endif #endif
c = va_arg (ap, char); c = va_arg (ap, char);
r = c; r = c;
eputs ("c:"); eputs (itoa (c)); eputs ("\n"); eputs ("c:");
eputs (itoa (c));
eputs ("\n");
va_end (ap); va_end (ap);
return r; return r;

View file

@ -59,8 +59,10 @@ main ()
printf ("tweetje: %d\n", f.bar[1]); printf ("tweetje: %d\n", f.bar[1]);
int *pf = &f; int *pf = &f;
if (*pf != 0x22) return 1; if (*pf != 0x22)
if (*(pf + 1) != 0x34) return 2; return 1;
if (*(pf + 1) != 0x34)
return 2;
struct foo *g = &f; struct foo *g = &f;
printf ("punter eentje: %d\n", g->bar[0]); printf ("punter eentje: %d\n", g->bar[0]);

View file

@ -56,10 +56,12 @@ main ()
printf ("b.i=%d\n", b.i); printf ("b.i=%d\n", b.i);
printf ("b.f.i=%d\n", b.f.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); 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; p->i = 2;
@ -72,26 +74,31 @@ main ()
printf ("p->i=%d\n", b.i); printf ("p->i=%d\n", b.i);
printf ("p->f.i=%d\n", p->f.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); 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; (*pp)->i = 3;
printf ("(*pp)->i=%d\n", b.i); printf ("(*pp)->i=%d\n", b.i);
printf ("sizeof i:%d\n", sizeof (p->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 __MESC__
//if ((offsetof (bar ,f)) != 4) return 6; //if ((offsetof (bar ,f)) != 4) return 6;
//#define offsetof(type, field) (&((type *)0)->field) //#define offsetof(type, field) (&((type *)0)->field)
if ((&((bar *)0)->f) != 4) return 6; if ((&((bar *) 0)->f) != 4)
return 6;
#else #else
if ((offsetof (bar ,f)) != 4) return 6; if ((offsetof (bar, f)) != 4)
return 6;
#endif #endif

View file

@ -43,8 +43,10 @@ main ()
printf ("f.i=%d\n", f.i); printf ("f.i=%d\n", f.i);
printf ("f.c=%c\n", f.c); printf ("f.c=%c\n", f.c);
if (f.i != 48) return 1; if (f.i != 48)
if (f.c != '0') return 1; return 1;
if (f.c != '0')
return 1;
return 0; return 0;
} }

View file

@ -22,11 +22,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
char const* help = char const *help = "All" " your" " base" " are";
"All"
" your"
" base"
" are";
int global_i = 1; int global_i = 1;
int *global_p = &global_i; int *global_p = &global_i;

View file

@ -21,7 +21,8 @@
#include <mes/lib.h> #include <mes/lib.h>
#include <stdio.h> #include <stdio.h>
union u { union u
{
int bar; int bar;
int baz; int baz;
}; };
@ -33,7 +34,8 @@ struct foo
struct anon struct anon
{ {
union { union
{
int bar; int bar;
int baz; int baz;
}; };
@ -45,15 +47,19 @@ main ()
{ {
struct foo f = { 2 }; struct foo f = { 2 };
printf ("f.u.bar=%d\n", f.u.bar); 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); 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); 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); printf ("a.baz=%d\n", a.baz);
if (a.baz != 2) return 1; if (a.baz != 2)
return 1;
return 0; return 0;
} }

View file

@ -23,7 +23,8 @@
char *list[2] = { "foo\n", "bar\n" }; char *list[2] = { "foo\n", "bar\n" };
struct foo { struct foo
{
int a; int a;
int b; int b;
int c; int c;
@ -45,9 +46,15 @@ main ()
int int_size = sizeof (int); int int_size = sizeof (int);
int ptr_size = sizeof (void *); int ptr_size = sizeof (void *);
int foo_size = sizeof (struct foo); int foo_size = sizeof (struct foo);
oputs ("int_size:"); oputs (itoa (int_size)); oputs ("\n"); oputs ("int_size:");
oputs ("ptr_size:"); oputs (itoa (ptr_size)); oputs ("\n"); oputs (itoa (int_size));
oputs ("foo_size:"); oputs (itoa (foo_size)); oputs ("\n"); oputs ("\n");
oputs ("ptr_size:");
oputs (itoa (ptr_size));
oputs ("\n");
oputs ("foo_size:");
oputs (itoa (foo_size));
oputs ("\n");
// FIXME: add *14, *18 // FIXME: add *14, *18
#if __i386__ #if __i386__
int foo_size_14 = 224; int foo_size_14 = 224;
@ -93,80 +100,112 @@ main ()
return 14; return 14;
struct foo *pfoo = 0; struct foo *pfoo = 0;
eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); eputs ("pfoo=");
eputs (itoa (pfoo));
eputs ("\n");
pfoo++; pfoo++;
eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); eputs ("pfoo=");
eputs (itoa (pfoo));
eputs ("\n");
if (pfoo != foo_size) if (pfoo != foo_size)
return 15; return 15;
pfoo--; pfoo--;
eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); eputs ("pfoo=");
eputs (itoa (pfoo));
eputs ("\n");
if (pfoo) if (pfoo)
return 16; return 16;
pfoo++; pfoo++;
eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); eputs ("pfoo=");
eputs (itoa (pfoo));
eputs ("\n");
if (pfoo != foo_size) if (pfoo != foo_size)
return 17; return 17;
long one = 1; long one = 1;
long two = 2; long two = 2;
pfoo = pfoo - one; pfoo = pfoo - one;
eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); eputs ("pfoo=");
eputs (itoa (pfoo));
eputs ("\n");
if (pfoo) if (pfoo)
return 18; return 18;
pfoo = pfoo + one; pfoo = pfoo + one;
eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); eputs ("pfoo=");
eputs (itoa (pfoo));
eputs ("\n");
if (pfoo != foo_size) if (pfoo != foo_size)
return 19; return 19;
pfoo -= one; pfoo -= one;
eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); eputs ("pfoo=");
eputs (itoa (pfoo));
eputs ("\n");
if (pfoo) if (pfoo)
return 20; return 20;
pfoo += one; pfoo += one;
eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); eputs ("pfoo=");
eputs (itoa (pfoo));
eputs ("\n");
if (pfoo != foo_size) if (pfoo != foo_size)
return 21; return 21;
eputs ("&one: "); eputs (itoa (&one)); eputs ("\n"); eputs ("&one: ");
eputs ("&two: "); eputs (itoa (&two)); eputs ("\n"); eputs (itoa (&one));
eputs ("\n");
eputs ("&two: ");
eputs (itoa (&two));
eputs ("\n");
if (&one - 1 != &two) if (&one - 1 != &two)
return 22; return 22;
struct foo *sym = foo_size + foo_size; struct foo *sym = foo_size + foo_size;
int i = sym + 16; int i = sym + 16;
eputs ("i="); eputs (itoa (i)); eputs ("\n"); eputs ("i=");
eputs (itoa (i));
eputs ("\n");
if (i != foo_size_18) if (i != foo_size_18)
return 23; return 23;
int d = 16; int d = 16;
i = sym + d; i = sym + d;
eputs ("i="); eputs (itoa (i)); eputs ("\n"); eputs ("i=");
eputs (itoa (i));
eputs ("\n");
if (i != foo_size_18) if (i != foo_size_18)
return 24; return 24;
i = sym - 16; i = sym - 16;
eputs ("i="); eputs (itoa (i)); eputs ("\n"); eputs ("i=");
eputs (itoa (i));
eputs ("\n");
if (i != -foo_size_14) if (i != -foo_size_14)
return 25; return 25;
i = sym - d; i = sym - d;
eputs ("i="); eputs (itoa (i)); eputs ("\n"); eputs ("i=");
eputs (itoa (i));
eputs ("\n");
if (i != -foo_size_14) if (i != -foo_size_14)
return 26; return 26;
i = sym - (struct foo *) foo_size; i = sym - (struct foo *) foo_size;
eputs ("i="); eputs (itoa (i)); eputs ("\n"); eputs ("i=");
eputs (itoa (i));
eputs ("\n");
if (i != 1) if (i != 1)
return 27; return 27;
pfoo = sym + 1; pfoo = sym + 1;
pfoo -= sym; pfoo -= sym;
eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); eputs ("pfoo=");
eputs (itoa (pfoo));
eputs ("\n");
if (pfoo != 1) if (pfoo != 1)
return 28; return 28;

View file

@ -22,12 +22,14 @@
#include <mes/lib.h> #include <mes/lib.h>
struct baz { struct baz
{
int i; int i;
int j; int j;
}; };
struct foo { struct foo
{
int **bar; int **bar;
}; };
@ -64,19 +66,30 @@ main ()
int *p = &i; int *p = &i;
struct foo f; struct foo f;
f.bar = &p; f.bar = &p;
eputs ("f.bar:"); eputs (itoa (f.bar)); eputs ("\n"); eputs ("f.bar:");
eputs (itoa (f.bar));
eputs ("\n");
add0 (&f.bar); add0 (&f.bar);
eputs ("f.bar:"); eputs (itoa (*f.bar)); eputs ("\n"); eputs ("f.bar:");
if (*f.bar != 0x11223344) return 1; eputs (itoa (*f.bar));
eputs ("\n");
if (*f.bar != 0x11223344)
return 1;
add1 (&f.bar); add1 (&f.bar);
eputs ("f.bar:"); eputs (itoa (f.bar)); eputs ("\n"); eputs ("f.bar:");
if (f.bar != 0x22334455) return 2; eputs (itoa (f.bar));
eputs ("\n");
if (f.bar != 0x22334455)
return 2;
add2 (&f.bar); add2 (&f.bar);
eputs ("f.bar:"); eputs (itoa (f.bar)); eputs ("\n"); eputs ("f.bar:");
if (f.bar != 0x33445566) return 3; eputs (itoa (f.bar));
eputs ("\n");
if (f.bar != 0x33445566)
return 3;
hash_ident[0] = 10; hash_ident[0] = 10;
*hash_ident = 0; *hash_ident = 0;
@ -84,11 +97,13 @@ main ()
struct baz b; struct baz b;
b.i = b.j = 1; b.i = b.j = 1;
if (b.i != 1) return 4; if (b.i != 1)
return 4;
struct baz *pb = &b; struct baz *pb = &b;
pb->i = pb->j = 1; pb->i = pb->j = 1;
if (pb->i != 1) return 5; if (pb->i != 1)
return 5;
return 0; return 0;
} }

View file

@ -22,12 +22,14 @@
#include <stdint.h> #include <stdint.h>
struct foo { struct foo
{
int i; int i;
void *p; void *p;
}; };
union bar { union bar
{
struct foo foo; struct foo foo;
}; };
@ -40,7 +42,8 @@ main ()
bar.foo.p = "hallo"; bar.foo.p = "hallo";
union bar *pb = &bar; union bar *pb = &bar;
if (pb->foo.i != 2) return 1; if (pb->foo.i != 2)
return 1;
return 0; return 0;
} }

View file

@ -48,29 +48,45 @@ main ()
if (b[3] != 55667788) if (b[3] != 55667788)
return 4; return 4;
eputs ("g_c[0]="); eputs (itoa (g_c[0])); eputs ("\n"); eputs ("g_c[0]=");
eputs ("g_c[1]="); eputs (itoa (g_c[1])); eputs ("\n"); 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)); 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) if (b[2] != 101)
return 5; return 5;
eputs ("b[3]:"); eputs (itoa (b[3])); eputs ("\n"); eputs ("b[3]:");
eputs (itoa (b[3]));
eputs ("\n");
if (b[3] != 111) if (b[3] != 111)
return 6; return 6;
int c[2] = { 201, 211 }; int c[2] = { 201, 211 };
eputs ("c[0]="); eputs (itoa (c[0])); eputs ("\n"); eputs ("c[0]=");
eputs ("c[1]="); eputs (itoa (c[1])); eputs ("\n"); eputs (itoa (c[0]));
eputs ("\n");
eputs ("c[1]=");
eputs (itoa (c[1]));
eputs ("\n");
memcpy (&b[4], c, 2 * sizeof (int)); 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) if (b[4] != 201)
return 7; return 7;
eputs ("b[5]:"); eputs (itoa (b[5])); eputs ("\n"); eputs ("b[5]:");
eputs (itoa (b[5]));
eputs ("\n");
if (b[5] != 211) if (b[5] != 211)
return 8; return 8;

View file

@ -22,11 +22,13 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
struct file { struct file
{
char buffer[1]; char buffer[1];
}; };
struct xfile { struct xfile
{
char *buffer; char *buffer;
}; };
@ -152,8 +154,10 @@ main ()
eputs (file.buffer); eputs (file.buffer);
memcpy (ps + 1, " ", 2); memcpy (ps + 1, " ", 2);
eputs (file.buffer); eputs (file.buffer);
eputs (itoa (ps[1])); eputs ("\n"); eputs (itoa (ps[1]));
eputs (itoa (((' ' << 8) + ' '))); eputs ("\n"); eputs ("\n");
eputs (itoa (((' ' << 8) + ' ')));
eputs ("\n");
if (ps[1] != ((' ' << 8) + ' ')) if (ps[1] != ((' ' << 8) + ' '))
return 40; return 40;
if (p[4] != '4') if (p[4] != '4')
@ -163,8 +167,10 @@ main ()
eputs (file.buffer); eputs (file.buffer);
ps[2] = ((' ' << 8) + ' '); ps[2] = ((' ' << 8) + ' ');
eputs (file.buffer); eputs (file.buffer);
eputs (itoa (ps[2])); eputs ("\n"); eputs (itoa (ps[2]));
eputs (itoa (((' ' << 8) + ' '))); eputs ("\n"); eputs ("\n");
eputs (itoa (((' ' << 8) + ' ')));
eputs ("\n");
if (ps[2] != ((' ' << 8) + ' ')) if (ps[2] != ((' ' << 8) + ' '))
return 42; return 42;
if (p[6] != '6') if (p[6] != '6')

View file

@ -34,6 +34,7 @@ struct bar
}; };
struct bar g_bar = { 101, 102 }; struct bar g_bar = { 101, 102 };
typedef struct bar bar_struct; typedef struct bar bar_struct;
typedef struct bar foo_struct; typedef struct bar foo_struct;

View file

@ -34,7 +34,8 @@ add (void *ptab, int *nb_ptr, void *data)
nb = *nb_ptr; nb = *nb_ptr;
pp = *(void ***) ptab; pp = *(void ***) ptab;
/* every power of two we double array size */ /* every power of two we double array size */
if ((nb & (nb - 1)) == 0) { if ((nb & (nb - 1)) == 0)
{
if (!nb) if (!nb)
nb_alloc = 1; nb_alloc = 1;
else else
@ -46,11 +47,13 @@ add (void *ptab, int *nb_ptr, void *data)
*nb_ptr = nb; *nb_ptr = nb;
} }
typedef struct file4 { typedef struct file4
{
char name[4]; char name[4];
} file4_struct; } file4_struct;
typedef struct file12 { typedef struct file12
{
int foo; int foo;
int bar; int bar;
char name[4]; char name[4];
@ -59,7 +62,8 @@ typedef struct file12 {
//#define file file4 //#define file file4
#define file file12 #define file file12
struct state { struct state
{
int bla; int bla;
char **paths; char **paths;
int path_count; int path_count;
@ -85,30 +89,56 @@ main ()
char *path_name = "foo:bar:baz"; char *path_name = "foo:bar:baz";
add (&s->paths, &s->path_count, path_name); 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 ("&PATHS=");
eputs ("&FILES="); eputs (itoa (&s->files)); eputs ("\n"); eputs (itoa (&s->paths));
eputs ("\n");
eputs ("&FILES=");
eputs (itoa (&s->files));
eputs ("\n");
// struct file *fs; // struct file *fs;
// eputs ("foo\n"); // eputs ("foo\n");
// fs = s->files[0]; // fs = s->files[0];
struct file *fs = s->files[0]; struct file *fs = s->files[0];
eputs ("add s= "); eputs (itoa (s)); eputs ("\n"); eputs ("add s= ");
eputs ("add fs= "); eputs (itoa (fs)); eputs ("\n"); eputs (itoa (s));
eputs ("&fs->[0]="); eputs (itoa (fs->name)); eputs ("\n"); eputs ("\n");
eputs ("fs->name="); eputs (fs->name); 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 ("*ps "); eputs (*s->paths); eputs ("\n"); 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->[0]=");
eputs ("fs->name="); eputs (fs->name); eputs ("\n"); 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 ("*ps "); eputs (*s->paths); eputs ("\n"); eputs (itoa (s->paths));
eputs ("\n");
eputs ("*ps ");
eputs (*s->paths);
eputs ("\n");
file = malloc (sizeof (struct file) + strlen (file_name)); file = malloc (sizeof (struct file) + strlen (file_name));
@ -119,28 +149,46 @@ main ()
struct file **pf = s->files; struct file **pf = s->files;
fs = pf[0]; fs = pf[0];
eputs ("\n"); 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]; fs = s->files[0];
eputs ("fs0*= "); eputs (itoa (fs)); eputs ("\n"); eputs ("fs0*= ");
eputs (itoa (fs));
eputs ("\n");
eputs ("\n"); eputs ("\n");
pf = s->files; pf = s->files;
fs = pf[1]; fs = pf[1];
eputs ("&fs1*= "); eputs (itoa (&pf[1])); eputs ("\n"); eputs ("&fs1*= ");
eputs ("fs1*= "); eputs (itoa (fs)); eputs ("\n"); eputs (itoa (&pf[1]));
fs = s->files[1];
eputs ("fs1*= "); eputs (itoa (fs)); eputs ("\n");
eputs ("\n"); 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]; fs = g_s.files[0];
eputs ("gfs0*= "); eputs (itoa (fs)); eputs ("\n"); eputs ("gfs0*= ");
fs = g_s.files[1]; eputs (itoa (fs));
eputs ("gfs1*= "); eputs (itoa (fs)); eputs ("\n");
eputs ("\n"); 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; return 0;

View file

@ -25,14 +25,18 @@ main ()
{ {
char *s = "int"; char *s = "int";
char c = s[0]; char c = s[0];
if (c != 'i') return 1; if (c != 'i')
return 1;
int i = ((unsigned char *) s)[0]; int i = ((unsigned char *) s)[0];
if (i != 'i') return 2; if (i != 'i')
return 2;
c = s[1]; c = s[1];
if (c != 'n') return 3; if (c != 'n')
return 3;
i = ((unsigned char *) s)[1]; i = ((unsigned char *) s)[1];
if (i != 'n') return 3; if (i != 'n')
return 3;
return 0; return 0;
} }

View file

@ -24,7 +24,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
struct symbol { struct symbol
{
int len; int len;
char str[10]; char str[10];
//int len; //int len;
@ -72,21 +73,30 @@ int
main () main ()
{ {
char *s = find0 (); char *s = find0 ();
eputs (s); eputs ("\n"); eputs (s);
if (strcmp (s, "foo")) return 1; eputs ("\n");
if (strcmp (list[0]->str, "foo")) return 2; if (strcmp (s, "foo"))
return 1;
if (strcmp (list[0]->str, "foo"))
return 2;
s = find1 (); s = find1 ();
eputs (s); eputs ("\n"); eputs (s);
if (strcmp (s, "bar")) return 3; eputs ("\n");
if (strcmp (list[1]->str, "bar")) return 4; if (strcmp (s, "bar"))
return 3;
if (strcmp (list[1]->str, "bar"))
return 4;
s = find2 (); s = find2 ();
eputs (s); eputs ("\n"); eputs (s);
if (strcmp (s, "pbar")) return 5; eputs ("\n");
if (strcmp (s, "pbar"))
return 5;
list[1]->len = 2; list[1]->len = 2;
if (list[1]->len != 2) return 6; if (list[1]->len != 2)
return 6;
return 0; return 0;
} }

View file

@ -26,7 +26,8 @@
struct foo; struct foo;
typedef struct foo foo_struct; typedef struct foo foo_struct;
struct foo { struct foo
{
//struct foo **foo; //struct foo **foo;
foo_struct **foo; foo_struct **foo;
}; };
@ -43,25 +44,46 @@ main ()
p = &foo.foo[0]; p = &foo.foo[0];
q = foo.foo; q = foo.foo;
eputs ("f:"); eputs (itoa (foo.foo)); eputs ("\n"); eputs ("f:");
eputs ("p:"); eputs (itoa (p)); eputs ("\n"); eputs (itoa (foo.foo));
eputs ("q:"); eputs (itoa (q)); eputs ("\n"); eputs ("\n");
if (q != p) return 1; eputs ("p:");
eputs (itoa (p));
eputs ("\n");
eputs ("q:");
eputs (itoa (q));
eputs ("\n");
if (q != p)
return 1;
p = &foo.foo[1]; p = &foo.foo[1];
q = foo.foo + 1; q = foo.foo + 1;
eputs ("f:"); eputs (itoa (foo.foo)); eputs ("\n"); eputs ("f:");
eputs ("p:"); eputs (itoa (p)); eputs ("\n"); eputs (itoa (foo.foo));
eputs ("q:"); eputs (itoa (q)); eputs ("\n"); eputs ("\n");
if (q != p) return 2; eputs ("p:");
eputs (itoa (p));
eputs ("\n");
eputs ("q:");
eputs (itoa (q));
eputs ("\n");
if (q != p)
return 2;
struct foo *pfoo = &foo; struct foo *pfoo = &foo;
p = &pfoo->foo[1]; p = &pfoo->foo[1];
q = pfoo->foo + 1; q = pfoo->foo + 1;
eputs ("f:"); eputs (itoa (pfoo->foo)); eputs ("\n"); eputs ("f:");
eputs ("p:"); eputs (itoa (p)); eputs ("\n"); eputs (itoa (pfoo->foo));
eputs ("q:"); eputs (itoa (q)); eputs ("\n"); eputs ("\n");
if (q != p) return 3; eputs ("p:");
eputs (itoa (p));
eputs ("\n");
eputs ("q:");
eputs (itoa (q));
eputs ("\n");
if (q != p)
return 3;
return 0; return 0;
} }

View file

@ -23,7 +23,8 @@
#include <inttypes.h> #include <inttypes.h>
#include <string.h> #include <string.h>
struct option { struct option
{
char const *name; char const *name;
uint8_t index; uint8_t index;
uint16_t flags; uint16_t flags;
@ -37,20 +38,28 @@ main ()
struct option o = { "output", 1, 11, 1 }; struct option o = { "output", 1, 11, 1 };
struct option v = { "version", 0, 0, 1 }; struct option v = { "version", 0, 0, 1 };
if (strcmp (h.name, "help")) return 1; if (strcmp (h.name, "help"))
if (h.index != 0) return 2; return 1;
if (h.flags != 10) return 3; if (h.index != 0)
return 2;
if (h.flags != 10)
return 3;
struct option *p = &o; struct option *p = &o;
if (strcmp (p->name, "output")) return 4; if (strcmp (p->name, "output"))
if (p->index != 1) return 5; return 4;
if (p->flags != 11) return 6; if (p->index != 1)
return 5;
if (p->flags != 11)
return 6;
p = &v; p = &v;
v.index = 2; v.index = 2;
p->flags = 12; p->flags = 12;
if (v.index != 2) return 7; if (v.index != 2)
if (v.flags != 12) return 8; return 7;
if (v.flags != 12)
return 8;
return 0; return 0;
} }

View file

@ -21,12 +21,14 @@
#include <mes/lib.h> #include <mes/lib.h>
#include <string.h> #include <string.h>
struct string { struct string
{
char *str; char *str;
int len; int len;
}; };
typedef struct biggie { typedef struct biggie
{
int a; int a;
int b; int b;
int c; int c;
@ -34,7 +36,8 @@ typedef struct biggie {
int len; int len;
} biggie; } biggie;
struct other { struct other
{
struct biggie big; struct biggie big;
}; };
@ -47,48 +50,66 @@ main ()
{ {
struct string s = { "hallo" }; struct string s = { "hallo" };
s.len = strlen (s.str); s.len = strlen (s.str);
eputs (s.str); eputs ("\n"); eputs (s.str);
eputs ("\n");
struct string t; struct string t;
t = s; t = s;
eputs (t.str); eputs ("\n"); eputs (t.str);
if (t.len != s.len) return 1; eputs ("\n");
if (strcmp (t.str, s.str)) return 2; if (t.len != s.len)
return 1;
if (strcmp (t.str, s.str))
return 2;
g_t = s; g_t = s;
eputs (g_t.str); eputs ("\n"); eputs (g_t.str);
if (g_t.len != s.len) return 3; eputs ("\n");
if (strcmp (g_t.str, s.str)) return 4; if (g_t.len != s.len)
return 3;
if (strcmp (g_t.str, s.str))
return 4;
struct biggie b; struct biggie b;
b.str = "hello"; b.str = "hello";
b.len = strlen (b.str); b.len = strlen (b.str);
eputs (b.str); eputs ("\n"); eputs (b.str);
eputs ("\n");
struct biggie tb; struct biggie tb;
tb = b; tb = b;
eputs (tb.str); eputs ("\n"); eputs (tb.str);
if (tb.len != b.len) return 5; eputs ("\n");
if (strcmp (tb.str, b.str)) return 6; if (tb.len != b.len)
return 5;
if (strcmp (tb.str, b.str))
return 6;
b.str = "bye"; b.str = "bye";
b.len = strlen (b.str); b.len = strlen (b.str);
eputs (b.str); eputs ("\n"); eputs (b.str);
eputs ("\n");
//struct biggie *pb = &tb; //struct biggie *pb = &tb;
biggie *pb = &tb; biggie *pb = &tb;
*pb = b; *pb = b;
eputs (tb.str); eputs ("\n"); eputs (tb.str);
if (tb.len != b.len) return 7; eputs ("\n");
if (strcmp (tb.str, b.str)) return 8; if (tb.len != b.len)
return 7;
if (strcmp (tb.str, b.str))
return 8;
tb.str = "there"; tb.str = "there";
tb.len = strlen (tb.str); tb.len = strlen (tb.str);
b = *pb; b = *pb;
eputs (b.str); eputs ("\n"); eputs (b.str);
if (b.len != tb.len) return 9; eputs ("\n");
if (strcmp (b.str, tb.str)) return 10; if (b.len != tb.len)
return 9;
if (strcmp (b.str, tb.str))
return 10;
char **x = &b.str; char **x = &b.str;
char *p; char *p;
@ -97,42 +118,62 @@ main ()
struct other o; struct other o;
struct other *po = &o; struct other *po = &o;
po->big = b; po->big = b;
eputs (o.big.str); eputs ("\n"); eputs (o.big.str);
if (o.big.len != b.len) return 13; eputs ("\n");
if (strcmp (o.big.str, b.str)) return 14; if (o.big.len != b.len)
return 13;
if (strcmp (o.big.str, b.str))
return 14;
po->big = *pb; po->big = *pb;
eputs (o.big.str); eputs ("\n"); eputs (o.big.str);
if (o.big.len != b.len) return 15; eputs ("\n");
if (strcmp (o.big.str, b.str)) return 16; if (o.big.len != b.len)
return 15;
if (strcmp (o.big.str, b.str))
return 16;
b.str = "* = *"; b.str = "* = *";
b.len = strlen (b.str); b.len = strlen (b.str);
eputs (b.str); eputs ("\n"); eputs (b.str);
eputs ("\n");
struct biggie *q = tab; struct biggie *q = tab;
pb = &b; pb = &b;
*q++ = *pb; *q++ = *pb;
eputs (tab[0].str); eputs ("\n"); eputs (tab[0].str);
if (tab[0].len != b.len) return 17; eputs ("\n");
if (strcmp (tab[0].str, b.str)) return 18; if (tab[0].len != b.len)
return 17;
if (strcmp (tab[0].str, b.str))
return 18;
tab[1] = tab[0]; tab[1] = tab[0];
eputs (tab[1].str); eputs ("\n"); eputs (tab[1].str);
if (tab[1].len != b.len) return 19; eputs ("\n");
if (strcmp (tab[1].str, b.str)) return 20; if (tab[1].len != b.len)
return 19;
if (strcmp (tab[1].str, b.str))
return 20;
tab[0].str = "burp"; tab[0].str = "burp";
tab[0].len = strlen (tab[1].str); tab[0].len = strlen (tab[1].str);
eputs (tab[0].str); eputs ("\n"); eputs (tab[0].str);
eputs ("\n");
b = tab[0]; b = tab[0];
eputs (b.str); eputs ("\n"); eputs (b.str);
if (b.len != tab[0].len) return 21; eputs ("\n");
if (strcmp (b.str, tab[0].str)) return 22; if (b.len != tab[0].len)
return 21;
if (strcmp (b.str, tab[0].str))
return 22;
tab[1] = b; tab[1] = b;
eputs (tab[1].str); eputs ("\n"); eputs (tab[1].str);
if (tab[1].len != b.len) return 23; eputs ("\n");
if (strcmp (tab[1].str, b.str)) return 24; if (tab[1].len != b.len)
return 23;
if (strcmp (tab[1].str, b.str))
return 24;
return 0; return 0;
} }

View file

@ -37,7 +37,8 @@ struct foo
struct anon struct anon
{ {
struct { struct
{
int bar; int bar;
int baz; int baz;
}; };
@ -49,19 +50,27 @@ main ()
{ {
struct foo f = { 0, 1, 2 }; struct foo f = { 0, 1, 2 };
f.s.baz = 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) if (f.s.bar != 1)
return 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) if (f.s.baz != 2)
return 2; return 2;
struct anon a = { 3, 4 }; struct anon a = { 3, 4 };
a.baz = 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) if (a.bar != 3)
return 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) if (a.baz != 4)
return 4; return 4;

View file

@ -34,6 +34,7 @@ struct sym tab[1] = {"foo", 1};
int int
main () main ()
{ {
eputs (tab[0].name); eputs ("\n"); eputs (tab[0].name);
eputs ("\n");
return 0; return 0;
} }

View file

@ -61,7 +61,9 @@ main ()
section.offset = 24; section.offset = 24;
int size = sizeof (struct sym); int size = sizeof (struct sym);
eputs ("size="); eputs (itoa (size)); eputs ("\n"); eputs ("size=");
eputs (itoa (size));
eputs ("\n");
if (size != sym_size) if (size != sym_size)
return 1; return 1;
struct section *psection = &section; struct section *psection = &section;
@ -69,18 +71,28 @@ main ()
struct sym *q = tab; struct sym *q = tab;
int i = (int) p; int i = (int) p;
i -= (int) q; i -= (int) q;
eputs ("diff="); eputs (itoa (i)); eputs ("\n"); eputs ("diff=");
eputs (itoa (i));
eputs ("\n");
if (i != sym_size) if (i != sym_size)
return 2; return 2;
for_each_elem(psection, 1, p, struct section) { for_each_elem (psection, 1, p, struct section)
eputs ("i="); eputs (itoa (p->index)); {
eputs (" name="); eputs (p->name); eputs ("\n"); eputs ("i=");
eputs (itoa (p->index));
eputs (" name=");
eputs (p->name);
eputs ("\n");
} }
for_each_elem2(psection, 1, p, struct section) { for_each_elem2 (psection, 1, p, struct section)
eputs ("i="); eputs (itoa (p->index)); {
eputs (" name="); eputs (p->name); eputs ("\n"); eputs ("i=");
eputs (itoa (p->index));
eputs (" name=");
eputs (p->name);
eputs ("\n");
} }
return 0; return 0;

View file

@ -58,7 +58,10 @@ main ()
p = &tab14; p = &tab14;
for (int i = 0; i < sizeof (struct foo13) * 2; i++) 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 (itoa (p[i]));
eputs ("\n"); eputs ("\n");
} }
@ -79,7 +82,10 @@ main ()
p = &tab16; p = &tab16;
for (int i = 0; i < sizeof (struct foo16) * 2; i++) 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 (itoa (p[i]));
eputs ("\n"); eputs ("\n");
} }

View file

@ -20,7 +20,8 @@
#include <mes/lib.h> #include <mes/lib.h>
struct file { struct file
{
char *ptr; char *ptr;
char buffer[20]; char buffer[20];
}; };
@ -36,7 +37,8 @@ main ()
eputs ("***\n"); eputs ("***\n");
f.ptr[1] = 'X'; f.ptr[1] = 'X';
eputs (f.ptr); eputs ("\n"); eputs (f.ptr);
eputs ("\n");
return 0; return 0;
} }

View file

@ -25,12 +25,14 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
typedef struct file { typedef struct file
{
char name[10]; char name[10];
} file_struct; } file_struct;
#define STACK_SIZE 2 #define STACK_SIZE 2
struct state { struct state
{
int bla; int bla;
file_struct *stack[STACK_SIZE]; file_struct *stack[STACK_SIZE];
char buf[100]; char buf[100];
@ -48,37 +50,47 @@ main ()
s.stack_ptr = s.stack; s.stack_ptr = s.stack;
ps->stack_ptr = ps->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"); 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"); eputs ("2\n");
struct file f = { "first.h" }; struct file f = { "first.h" };
#if 0 //__MESC__ #if 0 //__MESC__
strcpy (f.name, "first.h"); strcpy (f.name, "first.h");
#endif #endif
eputs (f.name); eputs ("\n"); eputs (f.name);
eputs ("\n");
*ps->stack_ptr = &f; *ps->stack_ptr = &f;
eputs ("3\n"); eputs ("3\n");
++ps->stack_ptr; ++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"); 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"); eputs ("5\n");
int i; int i;
i = ps->stack_ptr - ps->stack + STACK_SIZE; 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"); eputs ("6\n");
struct file f2 = { "second.h" }; struct file f2 = { "second.h" };
@ -89,14 +101,18 @@ main ()
*ps->stack_ptr = &f2; *ps->stack_ptr = &f2;
eputs ("7\n"); eputs ("7\n");
++ps->stack_ptr; ++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; if (ps->stack_ptr >= ps->stack + STACK_SIZE)
return 0;
struct file f3 = { "third.h" }; struct file f3 = { "third.h" };
*ps->stack_ptr = &f3; *ps->stack_ptr = &f3;
++ps->stack_ptr; ++ps->stack_ptr;

View file

@ -20,14 +20,23 @@
#include <mes/lib.h> #include <mes/lib.h>
struct info {int flag;}; struct info
struct foo {int length; char* string; struct info info;}; {
int flag;
};
struct foo
{
int length;
char *string;
struct info info;
};
struct foo stack[] = { {3, "foo", {11}}, {4, "baar", {12}} }; struct foo stack[] = { {3, "foo", {11}}, {4, "baar", {12}} };
int int
main () main ()
{ {
oputs (stack[1].string); oputs ("\n"); oputs (stack[1].string);
oputs ("\n");
return 0; return 0;
} }

View file

@ -20,15 +20,25 @@
#include <mes/lib.h> #include <mes/lib.h>
struct info {int flag;}; struct info
struct foo {int length; char* string; struct info info;}; {
int flag;
};
struct foo
{
int length;
char *string;
struct info info;
};
struct foo stack[] = { {3, "foo", {11}}, {4, "baar", {12}} }; struct foo stack[] = { {3, "foo", {11}}, {4, "baar", {12}} };
int int
main () main ()
{ {
oputs (stack[0].string); oputs ("\n"); oputs (stack[0].string);
oputs (stack[1].string); oputs ("\n"); oputs ("\n");
oputs (stack[1].string);
oputs ("\n");
struct foo *top = &stack[1]; struct foo *top = &stack[1];
int i; int i;
int j; int j;

View file

@ -18,7 +18,11 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
struct foo {int length; char* string;}; struct foo
{
int length;
char *string;
};
int int
main () main ()

View file

@ -20,11 +20,7 @@
struct bits struct bits
{ {
int int one:1, two:1, four:1, eightsixteen:2;
one: 1,
two : 1,
four: 1,
eightsixteen: 2;
}; };
union foo union foo

View file

@ -20,11 +20,7 @@
struct bits struct bits
{ {
int int one:1, two:1, four:1, eightsixteen:2;
one: 1,
two : 1,
four: 1,
eightsixteen: 2;
}; };
union foo union foo

View file

@ -19,7 +19,10 @@
*/ */
char global_c = -1; char global_c = -1;
struct foo {char type;}; struct foo
{
char type;
};
int int
main () main ()
{ {

View file

@ -33,6 +33,7 @@ struct bar
struct foo global_f = { 0, 11, 22 }; struct foo global_f = { 0, 11, 22 };
struct bar global_b = { 11 }; struct bar global_b = { 11 };
int i = 0x11223344; int i = 0x11223344;
struct foo foes[2] = { {0, 1, 2}, {0, 3, 4} }; struct foo foes[2] = { {0, 1, 2}, {0, 3, 4} };

View file

@ -29,6 +29,7 @@ struct foo
#define VSTACK_SIZE 2 #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) #define vstack (__vstack + 1)
int int

View file

@ -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 #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;
}

View file

@ -53,7 +53,9 @@ main ()
return 1; return 1;
if (sizeof (**p) != 1) if (sizeof (**p) != 1)
return 2; 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) if (sizeof (struct foo) != 20)
return 3; return 3;
struct foo f; struct foo f;

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