mescc: Mes C Library: Add M2-Planet support. WIP

* lib/m2/abtolc.: New file.
* lib/m2/accessc.: New file.
* lib/m2/atoic.: New file.
* lib/m2/chmodc.: New file.
* lib/m2/clock_gettimec.: New file.
* lib/m2/dupc.: New file.
* lib/m2/dup2c.: New file.
* lib/m2/eputsc.: New file.
* lib/m2/execvc.: New file.
* lib/m2/execvec.: New file.
* lib/m2/exitc.: New file.
* lib/m2/fdputcc.: New file.
* lib/m2/forkc.: New file.
* lib/m2/getcwdc.: New file.
* lib/m2/getenvc.: New file.
* lib/m2/isattyc.: New file.
* lib/m2/memchrc.: New file.
* lib/m2/memcmpc.: New file.
* lib/m2/memcpyc.: New file.
* lib/m2/mes_openc.: New file.
* lib/m2/ntoabc.: New file.
* lib/m2/openc.: New file.
* lib/m2/readc.: New file.
* lib/m2/setenvc.: New file.
* lib/m2/strcmpc.: New file.
* lib/m2/strcpyc.: New file.
* lib/m2/strlenc.: New file.
* lib/m2/strncmpc.: New file.
* lib/m2/timec.: New file.
* lib/m2/unlinkc.: New file.
* lib/m2/waitpidc.: New file.
* lib/m2/writec.: New file.
This commit is contained in:
Jan Nieuwenhuizen 2019-10-20 19:25:25 +02:00
parent 998a3fdc15
commit 8129434bfd
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
34 changed files with 1083 additions and 57 deletions

55
lib/m2/abtol.c Normal file
View File

@ -0,0 +1,55 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <ctype.h>
long
abtol (char **p, int base)
{
char *s = p[0];
int i = 0;
int sign_p = 0;
if (base == 0)
base = 10;
while (isspace (s[0]) != 0)
s = s + 1;
if (s[0] != 0 && s[0] == '+')
s = s + 1;
if (s[0] != 0 && s[0] == '-')
{
sign_p = 1;
s = s + 1;
}
while (isnumber (s[0], base) != 0)
{
i = i * base;
int m = '0';
if (s[0] > '9')
m = 'a' - 10;
i = i + s[0] - m;
s = s + 1;
}
p[0] = s;
if (sign_p != 0)
return -i;
return i;
}

21
lib/m2/access.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int access (char *file_name, int how);

26
lib/m2/atoi.c Normal file
View File

@ -0,0 +1,26 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int
atoi (char *string)
{
char *p = string;
return abtol (&p, 0);
}

21
lib/m2/chmod.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int chmod (char *file_name, int mode);

27
lib/m2/clock_gettime.c Normal file
View File

@ -0,0 +1,27 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
struct timespec
{
long tv_sec;
long tv_nsec;
};
int clock_gettime (int clk_id, struct timespec *tp);

21
lib/m2/dup.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int dup (int old);

21
lib/m2/dup2.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int dup2 (int old, int new);

29
lib/m2/eputs.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int __stderr;
int
eputs (char *s)
{
int i = strlen (s);
write (__stderr, s, i);
return 0;
}

25
lib/m2/execv.c Normal file
View File

@ -0,0 +1,25 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int
execv (char *file_name, char **argv)
{
return execve (file_name, argv, environ);
}

21
lib/m2/execve.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int execve (char *file_name, char **argv, char **envp);

29
lib/m2/exit.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
void _exit (int code);
void
exit (int code)
{
_exit (code);
}

28
lib/m2/fdputc.c Normal file
View File

@ -0,0 +1,28 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
int
fdputc (int c, int fd)
{
write (fd, &c, 1);
return 0;
}

21
lib/m2/fork.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int fork ();

21
lib/m2/getcwd.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
char *getcwd (char *buffer, size_t size);

43
lib/m2/getenv.c Normal file
View File

@ -0,0 +1,43 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <string.h>
#include <stdlib.h>
char *
getenv (char *s)
{
char **p = environ;
int length = strlen (s);
while (p[0] != 0)
{
if (strncmp (s, p[0], length) == 0)
{
char *q = p[0] + length;
if (q[0] == '=')
return q + 1;
}
p = p + 1;
}
return 0;
}

21
lib/m2/isatty.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int isatty (int filedes);

37
lib/m2/memchr.c Normal file
View File

@ -0,0 +1,37 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
void *
memchr (void *block, int c, size_t size)
{
char *p = block;
while (size != 0)
{
size = size - 1;
if (c == p[0])
return p;
p = p + 1;
}
return 0;
}

39
lib/m2/memcmp.c Normal file
View File

@ -0,0 +1,39 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
int
memcmp (void *s1, void *s2, size_t size)
{
if (size == 0)
return 0;
char *a = s1;
char *b = s2;
while (a[0] == b[0] && size > 0)
{
size = size - 1;
a = a + 1;
b = b + 1;
}
return a[0] - b[0];
}

39
lib/m2/memcpy.c Normal file
View File

@ -0,0 +1,39 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <string.h>
void *
memcpy (void *dest, void const *src, size_t n)
{
char *p = dest;
char const *q = src;
while (n != 0)
{
n = n - 1;
p[0] = q[0];
p = p + 1;
q = q + 1;
}
return dest;
}

29
lib/m2/mes_open.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int
mes_open (char *file_name, int flags, int mask)
{
__ungetc_init ();
int filedes = open (file_name, flags, mask);
if (filedes > 2)
__ungetc_clear (filedes);
return filedes;
}

69
lib/m2/ntoab.c Normal file
View File

@ -0,0 +1,69 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <assert.h>
#include <string.h>
char *__itoa_buf;
char *
ntoab (long x, int base, int signed_p)
{
if (! __itoa_buf)
__itoa_buf = malloc (20);
char *buf = __itoa_buf;
char *p = buf + 11;
p[0] = 0;
p = p - 1;
assert_msg (base > 0, "base > 0");
int sign_p = 0;
unsigned u;
if (signed_p != 0 && x < 0)
{
sign_p = 1;
u = -x;
}
else
u = x;
do
{
unsigned i;
i = u % base;
u = u / base;
if (i > 9)
p[0] = 'a' + i - 10;
else
p[0] = '0' + i;
p = p - 1;
}
while (u != 0);
if (sign_p && p[1] != '0')
{
p[0] = '-';
p = p - 1;
}
return p + 1;
}

21
lib/m2/open.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int open (char *file_name, int flags, int mask);

21
lib/m2/read.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int read (int filedes, void *buffer, int size);

52
lib/m2/setenv.c Normal file
View File

@ -0,0 +1,52 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <string.h>
#include <stdlib.h>
int
setenv (char *s, char *v, int overwrite_p)
{
char **p = environ;
int length = strlen (s);
while (p[0] != 0)
{
if (strncmp (s, p[0], length) == 0)
{
char *q = p[0] + length;
if (q[0] == '=')
break;
}
p = p + 1;
}
char *entry = malloc (length + strlen (v) + 2);
int end_p = p[0] == 0;
p[0] = entry;
strcpy (entry, s);
strcpy (entry + length, "=");
strcpy (entry + length + 1, v);
entry[length + strlen (v) + 2] = 0;
if (end_p)
p[1] = 0;
return 0;
}

33
lib/m2/strcmp.c Normal file
View File

@ -0,0 +1,33 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
int
strcmp (char *a, char *b)
{
while (a[0] != 0 && b[0] != 0 && a[0] == b[0])
{
a = a + 1;
b = b + 1;
}
return a[0] - b[0];
}

37
lib/m2/strcpy.c Normal file
View File

@ -0,0 +1,37 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
char *
strcpy (char *dest, char *src)
{
char *p = dest;
while (src[0] != 0)
{
p[0] = src[0];
p + p + 1;
src = src + 1;
}
p[0] = 0;
return dest;
}

30
lib/m2/strlen.c Normal file
View File

@ -0,0 +1,30 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int
strlen (char *s)
{
int i = 0;
while (s[i] != 0)
i = i + 1;
return i;
}

35
lib/m2/strncmp.c Normal file
View File

@ -0,0 +1,35 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int
strncmp (char const *a, char const *b, size_t size)
{
if (size == 0)
return 0;
while (a[0] != 0 && b[0] != 0 && a[0] == b[0] && size > 1)
{
size = size - 1;
a = a + 1;
b = b + 1;
}
return a[0] - b[0];
}

21
lib/m2/time.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int time (int *result);

21
lib/m2/unlink.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int unlink (char *file_name);

21
lib/m2/waitpid.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int waitpid (int pid, int *status_ptr, int options);

21
lib/m2/write.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int write (int fd, char *s, int length);

View File

@ -26,6 +26,7 @@
#include <sys/resource.h>
#include <unistd.h>
int errno;
int *__ungetc_buf;
int

View File

@ -26,7 +26,12 @@ MES = bin/mes-gcc
#MES_CPU = x86
M2_PLANET = M2-Planet
M2_PLANET_FLAGS = --architecture amd64
M2_PLANET_ARCH = x86
M2_PLANET_FUBAR = i386
#M2_PLANET_ARCH = amd64
#M2_PLANET_FUBAR = amd64
M2_PLANET_FLAGS = --debug --architecture $(M2_PLANET_ARCH)
CFLAGS:= \
$(CFLAGS) \
@ -58,12 +63,45 @@ MES_SOURCES = \
src/struct.c \
src/vector.c
LIB_SOURCES = \
lib/mes/eputs.c \
lib/mes/assert_msg.c \
lib/mes/itoa.c
M2_SOURCES = \
lib/m2/strlen.c \
lib/m2/eputs.c \
lib/m2/fdputc.c \
lib/m2/strncmp.c \
lib/m2/getenv.c \
lib/mes/fdputs.c \
lib/m2/ntoab.c \
lib/ctype/isdigit.c \
lib/ctype/isxdigit.c \
lib/ctype/isspace.c \
lib/ctype/isnumber.c \
lib/m2/abtol.c \
lib/m2/atoi.c \
lib/m2/memcpy.c \
lib/stdlib/realloc.c \
lib/m2/strcpy.c \
lib/m2/open.c \
lib/m2/mes_open.c \
lib/m2/read.c \
lib/mes/fdgetc.c \
lib/mes/itoa.c \
lib/mes/fdungetc.c \
lib/m2/setenv.c \
lib/m2/access.c \
lib/m2/chmod.c \
lib/m2/isatty.c \
lib/m2/fork.c \
lib/m2/execve.c \
lib/m2/execv.c \
lib/m2/waitpid.c \
lib/m2/clock_gettime.c \
lib/m2/time.c \
lib/m2/getcwd.c \
lib/m2/dup.c \
lib/m2/dup2.c \
lib/m2/unlink.c \
lib/m2/strcmp.c \
lib/m2/memcmp.c
M2_TODO = \
lib/m2/file_print.c \
@ -71,7 +109,6 @@ M2_TODO = \
lib/mes/fdgetc.c \
lib/mes/fdungetc.c
SOURCES = $(M2_SOURCES) $(LIB_SOURCES) $(MES_SOURCES)
INCLUDES = \
include/mes/builtins.h \
include/mes/constants.h \
@ -88,18 +125,21 @@ MES_LIBC = \
GCC_SOURCES = \
lib/mes/__mes_debug.c \
lib/mes/eputc.c \
lib/mes/eputs.c \
lib/mes/fdgetc.c \
lib/mes/fdputc.c \
lib/mes/fdputs.c \
lib/mes/fdungetc.c \
lib/mes/mes_open.c \
lib/mes/ntoab.c \
$(SOURCES)
lib/mes/itoa.c \
lib/mes/assert_msg.c \
$(MES_SOURCES)
mes-gcc: bin/mes-gcc
mes-m2: bin/mes-m2
bin/mes-gcc: $(MAKEFILES) $(GCC_SOURCES) $(INCLUDES) | bin
bin/mes-gcc: simple.make $(GCC_SOURCES) $(INCLUDES) | bin
$(CC) $(CFLAGS) $(GCC_SOURCES) -o $@
M2_PLANET_INCLUDES = \
@ -109,62 +149,91 @@ M2_PLANET_INCLUDES = \
include/mes/constants.h
M2_PLANET_PREFIX = ../M2-Planet
M2_PLANET_SOURCES = \
$(M2_PLANET_PREFIX)/test/common_amd64/functions/exit.c \
$(M2_PLANET_PREFIX)/test/common_amd64/functions/malloc.c \
$(M2_PLANET_PREFIX)/test/common_$(M2_PLANET_ARCH)/functions/exit.c \
$(M2_PLANET_PREFIX)/test/common_$(M2_PLANET_ARCH)/functions/malloc.c \
$(M2_PLANET_PREFIX)/functions/calloc.c \
$(M2_PLANET_INCLUDES:%.h=%.h.m2) \
$(SOURCES:%.c=%.c.m2)
$(M2_SOURCES:%.c=%.c.m2) \
$(MES_SOURCES:%.c=%.c.m2)
%.h.m2: %.h $(MAKEFILES)
@sed -r \
-e 's,^//,@@,' \
-e 's@^(#include.*)@/* \1 */@' \
$< \
| $(CC) -E -I include \
-D __M2_PLANET__=1 \
-D FUNCTION0=FUNCTION \
-D FUNCTION1=FUNCTION \
-D FUNCTION2=FUNCTION \
-D FUNCTION3=FUNCTION \
-D FUNCTIONN=FUNCTION \
-D const= \
-D long=SCM \
-D size_t=SCM \
-D ssize_t=SCM \
-D unsigned=SCM \
-include mes/m2.h \
-x c - \
| sed -r \
-e 's,^@@,//,' \
> $@ \
%.c.m2: %.c $(MAKEFILES)
@sed -r \
-e 's,^//,@@,' \
-e 's@^(#include.*)@/* \1 */@' \
$< \
| $(CC) -E -I include \
-D __M2_PLANET__=1 \
-D FUNCTION0=FUNCTION \
-D FUNCTION1=FUNCTION \
-D FUNCTION2=FUNCTION \
-D FUNCTION3=FUNCTION \
-D FUNCTIONN=FUNCTION \
-D const= \
-D long=SCM \
-D size_t=SCM \
-D ssize_t=SCM \
-D unsigned=SCM \
-include mes/m2.h \
-x c - \
| sed -r \
-e 's,^@@,//,' \
%.h.m2: %.h simple.make
@sed -r \
-e 's,^//,@@,' \
-e 's@^(#include.*)@/* \1 */@' \
$< \
| $(CC) -E -I include \
-D __M2_PLANET__=1 \
-D 'MES_VERSION="git"' \
-D 'MES_PKGDATADIR="/usr/local/share/mes"' \
-D FUNCTION0=FUNCTION \
-D FUNCTION1=FUNCTION \
-D FUNCTION2=FUNCTION \
-D FUNCTION3=FUNCTION \
-D FUNCTIONN=FUNCTION \
-D const= \
-D long=SCM \
-D size_t=SCM \
-D ssize_t=SCM \
-D unsigned=SCM \
-include mes/m2.h \
-x c - \
| sed -r \
-e 's,^@@,//,' \
> $@
bin/mes-m2: $(MAKEFILES) $(M2_PLANET_SOURCES) $(M2_PLANET_INCLUDES) | bin
%.c.m2: %.c simple.make
@sed -r \
-e 's,^//,@@,' \
-e 's@^(#include.*)@/* \1 */@' \
$< \
| $(CC) -E -I include \
-D __M2_PLANET__=1 \
-D 'MES_VERSION="git"' \
-D 'MES_PKGDATADIR="/usr/local/share/mes"' \
-D FUNCTION0=FUNCTION \
-D FUNCTION1=FUNCTION \
-D FUNCTION2=FUNCTION \
-D FUNCTION3=FUNCTION \
-D FUNCTIONN=FUNCTION \
-D EOF=-1 \
-D const= \
-D long=SCM \
-D size_t=SCM \
-D ssize_t=SCM \
-D unsigned=SCM \
-include mes/m2.h \
-x c - \
| sed -r \
-e 's,^@@,//,' \
> $@
bin/mes-m2.M1: simple.make $(M2_PLANET_SOURCES) $(M2_PLANET_INCLUDES) | bin
$(M2_PLANET) $(M2_PLANET_FLAGS) $(M2_PLANET_SOURCES:%=-f %) -o $@ || rm -f $@
bin/mes-m2.blood-elf.M1: bin/mes-m2.M1
# blood-elf --32 -f $< -o $@
blood-elf -f $< -o $@
bin/mes-m2.hex2: bin/mes-m2.blood-elf.M1 $(M2_PLANET_PREFIX)
M1 \
-f $(M2_PLANET_PREFIX)/test/common_$(M2_PLANET_ARCH)/$(M2_PLANET_ARCH)_defs.M1 \
-f $(M2_PLANET_PREFIX)/test/common_$(M2_PLANET_ARCH)/libc-core.M1 \
-f bin/mes-m2.M1 \
-f bin/mes-m2.blood-elf.M1 \
--LittleEndian \
--architecture $(M2_PLANET_ARCH) \
-o $@
bin/mes-m2: bin/mes-m2.hex2
hex2 \
-f $(M2_PLANET_PREFIX)/test/common_$(M2_PLANET_ARCH)/ELF-$(M2_PLANET_FUBAR)-debug.hex2 \
-f bin/mes-m2.hex2 \
--LittleEndian \
--architecture $(M2_PLANET_ARCH) \
--BaseAddress 0x00600000 \
--exec_enable \
-o $@
# Clean up after ourselves
.PHONY: clean
clean: