mirror of
https://github.com/fosslinux/live-bootstrap.git
synced 2026-03-14 23:35:24 +01:00
Add mes and mescc-tools-extra
mescc-tools-extra contains two important tools: - cp - chmod mes first builds itself from a mes 0.21 seed as used by guix, and then builds a mes 0.22 and then mes 0.22 using that created mes 0.22. It does /not/ use bootstrap.sh as we don't have a proper shell at this point, it has been manually adapted for kaem.
This commit is contained in:
parent
2706e07556
commit
649d7b68dc
1029 changed files with 120985 additions and 18 deletions
29
sysa/mes-0.22/lib/stdio/clearerr.c
Normal file
29
sysa/mes-0.22/lib/stdio/clearerr.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* GNU Mes is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void
|
||||
clearerr (FILE * stream)
|
||||
{
|
||||
errno = 0;
|
||||
}
|
||||
29
sysa/mes-0.22/lib/stdio/fclose.c
Normal file
29
sysa/mes-0.22/lib/stdio/fclose.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* -*-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 <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
fclose (FILE * stream)
|
||||
{
|
||||
int fd = (long) stream;
|
||||
return close (fd);
|
||||
}
|
||||
27
sysa/mes-0.22/lib/stdio/fdopen.c
Normal file
27
sysa/mes-0.22/lib/stdio/fdopen.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* -*-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 <stdio.h>
|
||||
|
||||
FILE *
|
||||
fdopen (int fd, char const *mode)
|
||||
{
|
||||
return (FILE *) (long) fd;
|
||||
}
|
||||
30
sysa/mes-0.22/lib/stdio/feof.c
Normal file
30
sysa/mes-0.22/lib/stdio/feof.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* GNU Mes is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
feof (FILE * stream)
|
||||
{
|
||||
char c = fgetc (stream);
|
||||
if (c != EOF)
|
||||
ungetc (c, stream);
|
||||
return c == EOF;
|
||||
}
|
||||
30
sysa/mes-0.22/lib/stdio/ferror.c
Normal file
30
sysa/mes-0.22/lib/stdio/ferror.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* -*-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 <stdio.h>
|
||||
|
||||
int
|
||||
ferror (FILE * stream)
|
||||
{
|
||||
int fd = (long) stream;
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
32
sysa/mes-0.22/lib/stdio/fflush.c
Normal file
32
sysa/mes-0.22/lib/stdio/fflush.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* -*-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 <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
fflush (FILE * stream)
|
||||
{
|
||||
int filedes = (long) stream;
|
||||
if (filedes < 3)
|
||||
return 0;
|
||||
return fsync (filedes);
|
||||
}
|
||||
27
sysa/mes-0.22/lib/stdio/fgetc.c
Normal file
27
sysa/mes-0.22/lib/stdio/fgetc.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* -*-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 <stdio.h>
|
||||
|
||||
int
|
||||
fgetc (FILE * stream)
|
||||
{
|
||||
return fdgetc ((long) stream);
|
||||
}
|
||||
28
sysa/mes-0.22/lib/stdio/fgets.c
Normal file
28
sysa/mes-0.22/lib/stdio/fgets.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 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 <stdio.h>
|
||||
|
||||
char *
|
||||
fgets (char *s, int count, FILE * stream)
|
||||
{
|
||||
return fdgets (s, count, (int) (long) stream);
|
||||
}
|
||||
27
sysa/mes-0.22/lib/stdio/fileno.c
Normal file
27
sysa/mes-0.22/lib/stdio/fileno.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* GNU Mes is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
fileno (FILE * stream)
|
||||
{
|
||||
return (int) (long) stream;
|
||||
}
|
||||
74
sysa/mes-0.22/lib/stdio/fopen.c
Normal file
74
sysa/mes-0.22/lib/stdio/fopen.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2018 Jeremiah Orians <jeremiah@pdp10.guru>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* GNU Mes is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
FILE *
|
||||
fopen (char const *file_name, char const *opentype)
|
||||
{
|
||||
if (__mes_debug ())
|
||||
{
|
||||
eputs ("fopen ");
|
||||
eputs (file_name);
|
||||
eputs (" ");
|
||||
eputs (opentype);
|
||||
eputs ("\n");
|
||||
}
|
||||
|
||||
int fd;
|
||||
int mode = 0600;
|
||||
if ((opentype[0] == 'a' || !strcmp (opentype, "r+")) && !access (file_name, O_RDONLY))
|
||||
{
|
||||
int flags = O_RDWR;
|
||||
if (opentype[0] == 'a')
|
||||
flags |= O_APPEND;
|
||||
fd = _open3 (file_name, flags, mode);
|
||||
}
|
||||
else if (opentype[0] == 'w' || opentype[0] == 'a' || !strcmp (opentype, "r+"))
|
||||
{
|
||||
char *plus_p = strchr (opentype, '+');
|
||||
int flags = plus_p ? O_RDWR | O_CREAT : O_WRONLY | O_CREAT | O_TRUNC;
|
||||
fd = _open3 (file_name, flags, mode);
|
||||
}
|
||||
else
|
||||
fd = _open3 (file_name, O_RDONLY, 0);
|
||||
|
||||
if (__mes_debug ())
|
||||
{
|
||||
eputs (" => fd=");
|
||||
eputs (itoa (fd));
|
||||
eputs ("\n");
|
||||
}
|
||||
|
||||
if (!fd)
|
||||
{
|
||||
eputs (" ***MES LIB C*** fopen of stdin: signal me in band\n");
|
||||
assert (0);
|
||||
}
|
||||
if (fd < 0)
|
||||
fd = 0;
|
||||
return (FILE *) (long) fd;
|
||||
}
|
||||
33
sysa/mes-0.22/lib/stdio/fprintf.c
Normal file
33
sysa/mes-0.22/lib/stdio/fprintf.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* -*-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 <mes/lib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
fprintf (FILE * stream, char const *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
int r = vfprintf (stream, format, ap);
|
||||
va_end (ap);
|
||||
return r;
|
||||
}
|
||||
27
sysa/mes-0.22/lib/stdio/fputc.c
Normal file
27
sysa/mes-0.22/lib/stdio/fputc.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* -*-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 <stdio.h>
|
||||
|
||||
int
|
||||
fputc (int c, FILE * stream)
|
||||
{
|
||||
return fdputc (c, (long) stream);
|
||||
}
|
||||
27
sysa/mes-0.22/lib/stdio/fputs.c
Normal file
27
sysa/mes-0.22/lib/stdio/fputs.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* -*-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 <stdio.h>
|
||||
|
||||
int
|
||||
fputs (char const *s, FILE * stream)
|
||||
{
|
||||
return fdputs (s, (long) stream);
|
||||
}
|
||||
76
sysa/mes-0.22/lib/stdio/fread.c
Normal file
76
sysa/mes-0.22/lib/stdio/fread.c
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/* -*-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 <mes/lib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
__fungetc_p (FILE * stream)
|
||||
{
|
||||
return __ungetc_p ((int) (long) stream);
|
||||
}
|
||||
|
||||
size_t
|
||||
fread (void *data, size_t size, size_t count, FILE * stream)
|
||||
{
|
||||
if (!size || !count)
|
||||
return 0;
|
||||
|
||||
size_t todo = size * count;
|
||||
char *buf = (char *) data;
|
||||
|
||||
int bytes = 0;
|
||||
while (__fungetc_p (stream) && todo-- && ++bytes)
|
||||
*buf++ = fgetc (stream);
|
||||
int filedes = (long) stream;
|
||||
if (todo)
|
||||
{
|
||||
int r = read (filedes, buf, todo);
|
||||
if (r < 0 && !bytes)
|
||||
bytes = r;
|
||||
else
|
||||
bytes += r;
|
||||
}
|
||||
|
||||
if (__mes_debug ())
|
||||
{
|
||||
static char debug_buf[4096];
|
||||
eputs ("fread fd=");
|
||||
eputs (itoa (filedes));
|
||||
eputs (" bytes=");
|
||||
eputs (itoa (bytes));
|
||||
eputs ("\n");
|
||||
if (bytes > 0 && bytes < sizeof (debug_buf))
|
||||
{
|
||||
strncpy (debug_buf, data, bytes);
|
||||
buf[bytes] = 0;
|
||||
eputs ("fread buf=");
|
||||
eputs (debug_buf);
|
||||
eputs ("\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (bytes > 0)
|
||||
return bytes / size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
28
sysa/mes-0.22/lib/stdio/freopen.c
Normal file
28
sysa/mes-0.22/lib/stdio/freopen.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* GNU Mes is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
FILE *
|
||||
freopen (char const *file_name, char const *opentype, FILE * stream)
|
||||
{
|
||||
fclose (stream);
|
||||
return fopen (file_name, opentype);
|
||||
}
|
||||
33
sysa/mes-0.22/lib/stdio/fscanf.c
Normal file
33
sysa/mes-0.22/lib/stdio/fscanf.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* -*-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 <mes/lib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
fscanf (FILE * stream, char const *template, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, template);
|
||||
int r = vfscanf (stream, template, ap);
|
||||
va_end (ap);
|
||||
return r;
|
||||
}
|
||||
41
sysa/mes-0.22/lib/stdio/fseek.c
Normal file
41
sysa/mes-0.22/lib/stdio/fseek.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* -*-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 <mes/lib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
fseek (FILE * stream, long offset, int whence)
|
||||
{
|
||||
int filedes = (long) stream;
|
||||
off_t pos = lseek (filedes, offset, whence);
|
||||
if (__mes_debug ())
|
||||
{
|
||||
eputs ("fread fd=");
|
||||
eputs (itoa (filedes));
|
||||
eputs (" =>");
|
||||
eputs (itoa (pos));
|
||||
eputs ("\n");
|
||||
}
|
||||
if (pos >= 0)
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
29
sysa/mes-0.22/lib/stdio/ftell.c
Normal file
29
sysa/mes-0.22/lib/stdio/ftell.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* -*-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 <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
long
|
||||
ftell (FILE * stream)
|
||||
{
|
||||
return lseek ((int) (long) stream, 0, SEEK_CUR);
|
||||
}
|
||||
52
sysa/mes-0.22/lib/stdio/fwrite.c
Normal file
52
sysa/mes-0.22/lib/stdio/fwrite.c
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* -*-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 <mes/lib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
size_t
|
||||
fwrite (void const *data, size_t size, size_t count, FILE * stream)
|
||||
{
|
||||
if (__mes_debug () > 1)
|
||||
{
|
||||
eputs ("fwrite ");
|
||||
eputs (itoa ((int) (long) stream));
|
||||
eputs (" ");
|
||||
eputs (itoa (size));
|
||||
eputs ("\n");
|
||||
}
|
||||
|
||||
if (!size || !count)
|
||||
return 0;
|
||||
int filedes = (long) stream;
|
||||
int bytes = write (filedes, data, size * count);
|
||||
|
||||
if (__mes_debug () > 2)
|
||||
{
|
||||
eputs (" => ");
|
||||
eputs (itoa (bytes));
|
||||
eputs ("\n");
|
||||
}
|
||||
|
||||
if (bytes > 0)
|
||||
return bytes / size;
|
||||
return 0;
|
||||
}
|
||||
27
sysa/mes-0.22/lib/stdio/getc.c
Normal file
27
sysa/mes-0.22/lib/stdio/getc.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* -*-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 <stdio.h>
|
||||
|
||||
int
|
||||
getc (FILE * stream)
|
||||
{
|
||||
return fdgetc ((long) stream);
|
||||
}
|
||||
27
sysa/mes-0.22/lib/stdio/getchar.c
Normal file
27
sysa/mes-0.22/lib/stdio/getchar.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* -*-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 <stdio.h>
|
||||
|
||||
int
|
||||
getchar ()
|
||||
{
|
||||
return fdgetc (__stdin);
|
||||
}
|
||||
30
sysa/mes-0.22/lib/stdio/perror.c
Normal file
30
sysa/mes-0.22/lib/stdio/perror.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 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 <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
perror (char const *message)
|
||||
{
|
||||
fprintf (stderr, "%s: %s\n", strerror (errno), message);
|
||||
}
|
||||
39
sysa/mes-0.22/lib/stdio/printf.c
Normal file
39
sysa/mes-0.22/lib/stdio/printf.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* -*-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 <mes/lib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
printf (char const *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int r;
|
||||
#if __GNUC__ && __x86_64__ && !SYSTEM_LIBC
|
||||
#define __FUNCTION_ARGS 1
|
||||
ap += (__FOO_VARARGS + (__FUNCTION_ARGS << 1)) << 3;
|
||||
#undef __FUNCTION_ARGS
|
||||
#endif
|
||||
va_start (ap, format);
|
||||
r = vprintf (format, ap);
|
||||
va_end (ap);
|
||||
return r;
|
||||
}
|
||||
27
sysa/mes-0.22/lib/stdio/putc.c
Normal file
27
sysa/mes-0.22/lib/stdio/putc.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* -*-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 <stdio.h>
|
||||
|
||||
int
|
||||
putc (int c, FILE * stream)
|
||||
{
|
||||
return fdputc (c, (long) stream);
|
||||
}
|
||||
28
sysa/mes-0.22/lib/stdio/putchar.c
Normal file
28
sysa/mes-0.22/lib/stdio/putchar.c
Normal 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 <stdio.h>
|
||||
|
||||
int
|
||||
putchar (int c)
|
||||
{
|
||||
write (STDOUT, (char *) &c, 1);
|
||||
return 0;
|
||||
}
|
||||
34
sysa/mes-0.22/lib/stdio/remove.c
Normal file
34
sysa/mes-0.22/lib/stdio/remove.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* -*-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 <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
remove (char const *file_name)
|
||||
{
|
||||
struct stat buf;
|
||||
if (stat (file_name, &buf) < 0)
|
||||
return -1;
|
||||
if (S_ISDIR (buf.st_mode))
|
||||
return rmdir (file_name);
|
||||
return unlink (file_name);
|
||||
}
|
||||
39
sysa/mes-0.22/lib/stdio/snprintf.c
Normal file
39
sysa/mes-0.22/lib/stdio/snprintf.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* -*-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 <mes/lib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
snprintf (char *str, size_t size, char const *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int r;
|
||||
#if __GNUC__ && __x86_64__ && !SYSTEM_LIBC
|
||||
#define __FUNCTION_ARGS 3
|
||||
ap += (__FOO_VARARGS + (__FUNCTION_ARGS << 1)) << 3;
|
||||
#undef __FUNCTION_ARGS
|
||||
#endif
|
||||
va_start (ap, format);
|
||||
r = vsnprintf (str, size, format, ap);
|
||||
va_end (ap);
|
||||
return r;
|
||||
}
|
||||
39
sysa/mes-0.22/lib/stdio/sprintf.c
Normal file
39
sysa/mes-0.22/lib/stdio/sprintf.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* -*-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 <mes/lib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
sprintf (char *str, char const *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int r;
|
||||
#if __GNUC__ && __x86_64__ && !SYSTEM_LIBC
|
||||
#define __FUNCTION_ARGS 2
|
||||
ap += (__FOO_VARARGS + (__FUNCTION_ARGS << 1)) << 3;
|
||||
#undef __FUNCTION_ARGS
|
||||
#endif
|
||||
va_start (ap, format);
|
||||
r = vsprintf (str, format, ap);
|
||||
va_end (ap);
|
||||
return r;
|
||||
}
|
||||
33
sysa/mes-0.22/lib/stdio/sscanf.c
Normal file
33
sysa/mes-0.22/lib/stdio/sscanf.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* -*-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 <mes/lib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
sscanf (char const *str, char const *template, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, template);
|
||||
int r = vsscanf (str, template, ap);
|
||||
va_end (ap);
|
||||
return r;
|
||||
}
|
||||
27
sysa/mes-0.22/lib/stdio/ungetc.c
Normal file
27
sysa/mes-0.22/lib/stdio/ungetc.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* -*-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 <stdio.h>
|
||||
|
||||
int
|
||||
ungetc (int c, FILE * stream)
|
||||
{
|
||||
return fdungetc (c, (long) stream);
|
||||
}
|
||||
252
sysa/mes-0.22/lib/stdio/vfprintf.c
Normal file
252
sysa/mes-0.22/lib/stdio/vfprintf.c
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
/* -*-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 <mes/lib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
vfprintf (FILE * f, char const *format, va_list ap)
|
||||
{
|
||||
int fd = (long) f;
|
||||
char const *p = format;
|
||||
int count = 0;
|
||||
while (*p)
|
||||
if (*p != '%')
|
||||
{
|
||||
count++;
|
||||
fputc (*p++, f);
|
||||
}
|
||||
else
|
||||
{
|
||||
p++;
|
||||
char c = *p;
|
||||
int left_p = 0;
|
||||
int precision = -1;
|
||||
int width = -1;
|
||||
if (c == '-')
|
||||
{
|
||||
left_p = 1;
|
||||
c = *++p;
|
||||
}
|
||||
char pad = ' ';
|
||||
if (c == ' ')
|
||||
{
|
||||
pad = c;
|
||||
c = *p++;
|
||||
}
|
||||
if (c == '0')
|
||||
{
|
||||
pad = c;
|
||||
c = *p++;
|
||||
}
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
width = abtol (&p, 10);
|
||||
c = *p;
|
||||
}
|
||||
else if (c == '*')
|
||||
{
|
||||
width = va_arg (ap, int);
|
||||
c = *++p;
|
||||
}
|
||||
if (c == '.')
|
||||
{
|
||||
c = *++p;
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
precision = abtol (&p, 10);
|
||||
c = *p;
|
||||
}
|
||||
else if (c == '*')
|
||||
{
|
||||
precision = va_arg (ap, int);
|
||||
c = *++p;
|
||||
}
|
||||
}
|
||||
if (c == 'l')
|
||||
c = *++p;
|
||||
if (c == 'l')
|
||||
{
|
||||
eputs ("vfprintf: skipping second: l\n");
|
||||
c = *++p;
|
||||
}
|
||||
switch (c)
|
||||
{
|
||||
case '%':
|
||||
{
|
||||
fputc (*p, f);
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
case 'c':
|
||||
{
|
||||
char _c;
|
||||
_c = va_arg (ap, long);
|
||||
fputc (_c, f);
|
||||
break;
|
||||
}
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'o':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'X':
|
||||
{
|
||||
long d = va_arg (ap, long);
|
||||
int base = c == 'o' ? 8 : c == 'x' || c == 'X' ? 16 : 10;
|
||||
char *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X');
|
||||
if (c == 'X')
|
||||
strupr (s);
|
||||
int length = strlen (s);
|
||||
if (precision == -1)
|
||||
precision = length;
|
||||
if (!left_p)
|
||||
{
|
||||
while (width-- > precision)
|
||||
{
|
||||
fputc (pad, f);
|
||||
count++;
|
||||
}
|
||||
while (precision > length)
|
||||
{
|
||||
fputc ('0', f);
|
||||
precision--;
|
||||
width--;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
while (*s)
|
||||
{
|
||||
if (precision-- <= 0)
|
||||
break;
|
||||
width--;
|
||||
fputc (*s++, f);
|
||||
count++;
|
||||
}
|
||||
while (width > 0)
|
||||
{
|
||||
width--;
|
||||
fputc (pad, f);
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 's':
|
||||
{
|
||||
char *s = va_arg (ap, char *);
|
||||
int length = strlen (s);
|
||||
if (precision == -1)
|
||||
precision = length;
|
||||
if (!left_p)
|
||||
{
|
||||
while (width-- > precision)
|
||||
{
|
||||
fputc (pad, f);
|
||||
count++;
|
||||
}
|
||||
while (precision > length)
|
||||
{
|
||||
fputc (' ', f);
|
||||
precision--;
|
||||
width--;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
while (*s)
|
||||
{
|
||||
if (precision-- <= 0)
|
||||
break;
|
||||
width--;
|
||||
fputc (*s++, f);
|
||||
count++;
|
||||
}
|
||||
while (width > 0)
|
||||
{
|
||||
width--;
|
||||
fputc (pad, f);
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'f':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
{
|
||||
double d = va_arg8 (ap, double);
|
||||
char *s = dtoab (d, 10, 1);
|
||||
if (c == 'E' || c == 'G')
|
||||
strupr (s);
|
||||
int length = strlen (s);
|
||||
if (precision == -1)
|
||||
precision = length;
|
||||
if (!left_p)
|
||||
{
|
||||
while (width-- > precision)
|
||||
{
|
||||
fputc (pad, f);
|
||||
count++;
|
||||
}
|
||||
while (precision > length)
|
||||
{
|
||||
fputc (' ', f);
|
||||
precision--;
|
||||
width--;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
while (*s)
|
||||
{
|
||||
if (precision-- <= 0)
|
||||
break;
|
||||
width--;
|
||||
fputc (*s++, f);
|
||||
count++;
|
||||
}
|
||||
while (width > 0)
|
||||
{
|
||||
width--;
|
||||
fputc (pad, f);
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'n':
|
||||
{
|
||||
int *n = va_arg (ap, int *);
|
||||
*n = count;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
eputs ("vfprintf: not supported: %:");
|
||||
eputc (c);
|
||||
eputs ("\n");
|
||||
p++;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
va_end (ap);
|
||||
return 0;
|
||||
}
|
||||
122
sysa/mes-0.22/lib/stdio/vfscanf.c
Normal file
122
sysa/mes-0.22/lib/stdio/vfscanf.c
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/* -*-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 <mes/lib.h>
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
vfscanf (FILE * stream, char const *template, va_list ap)
|
||||
{
|
||||
char p = fgetc (stream);
|
||||
char const *t = template;
|
||||
int count = 0;
|
||||
while (*t && p != EOF)
|
||||
if (*t != '%')
|
||||
{
|
||||
t++;
|
||||
p = fgetc (stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
t++;
|
||||
char c = *t;
|
||||
if (c == 'l')
|
||||
c = *++t;
|
||||
switch (c)
|
||||
{
|
||||
case '%':
|
||||
{
|
||||
p = fgetc (stream);
|
||||
break;
|
||||
}
|
||||
case 'c':
|
||||
{
|
||||
char *c = va_arg (ap, char *);
|
||||
*c = p;
|
||||
p = fgetc (stream);
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'u':
|
||||
{
|
||||
int *d = va_arg (ap, int *);
|
||||
char buf[20];
|
||||
char *q = buf;
|
||||
if (p == '+' || p == '-')
|
||||
{
|
||||
*q++ = p;
|
||||
p = fgetc (stream);
|
||||
}
|
||||
while (isdigit (p))
|
||||
{
|
||||
*q++ = p;
|
||||
p = fgetc (stream);
|
||||
}
|
||||
ungetc (p, stream);
|
||||
*q = 0;
|
||||
q = buf;
|
||||
*d = abtol (&q, 10);
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
case 'e':
|
||||
case 'f':
|
||||
case 'g':
|
||||
case 'E':
|
||||
case 'G':
|
||||
{
|
||||
float *f = va_arg (ap, float *);
|
||||
char buf[20];
|
||||
char *q = buf;
|
||||
if (p == '+' || p == '-')
|
||||
{
|
||||
*q++ = p;
|
||||
p = fgetc (stream);
|
||||
}
|
||||
while (isdigit (p))
|
||||
{
|
||||
*q++ = p;
|
||||
p = fgetc (stream);
|
||||
}
|
||||
ungetc (p, stream);
|
||||
*q = 0;
|
||||
q = buf;
|
||||
*f = strtod (q, &q);
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
eputs ("vsscanf: not supported: %:");
|
||||
eputc (c);
|
||||
eputs ("\n");
|
||||
t++;
|
||||
p = fgetc (stream);
|
||||
}
|
||||
}
|
||||
t++;
|
||||
}
|
||||
va_end (ap);
|
||||
return count;
|
||||
}
|
||||
29
sysa/mes-0.22/lib/stdio/vprintf.c
Normal file
29
sysa/mes-0.22/lib/stdio/vprintf.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* -*-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 <mes/lib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
vprintf (char const *format, va_list ap)
|
||||
{
|
||||
return vfprintf (stdout, format, ap);
|
||||
}
|
||||
275
sysa/mes-0.22/lib/stdio/vsnprintf.c
Normal file
275
sysa/mes-0.22/lib/stdio/vsnprintf.c
Normal file
|
|
@ -0,0 +1,275 @@
|
|||
/* -*-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 <mes/lib.h>
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
vsnprintf (char *str, size_t size, char const *format, va_list ap)
|
||||
{
|
||||
char const *p = format;
|
||||
int count = 0;
|
||||
char c;
|
||||
while (*p)
|
||||
if (*p != '%')
|
||||
{
|
||||
c = *p++;
|
||||
if (count < size)
|
||||
*str++ = c;
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
p++;
|
||||
c = *p;
|
||||
int left_p = 0;
|
||||
int precision = -1;
|
||||
int width = -1;
|
||||
if (c == '-')
|
||||
{
|
||||
left_p = 1;
|
||||
c = *++p;
|
||||
}
|
||||
char pad = ' ';
|
||||
if (c == ' ')
|
||||
{
|
||||
pad = c;
|
||||
c = *p++;
|
||||
}
|
||||
if (c == '0')
|
||||
{
|
||||
pad = c;
|
||||
c = *p++;
|
||||
}
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
width = abtol (&p, 10);
|
||||
c = *p;
|
||||
}
|
||||
else if (c == '*')
|
||||
{
|
||||
width = va_arg (ap, long);
|
||||
c = *++p;
|
||||
}
|
||||
if (c == '.')
|
||||
{
|
||||
c = *++p;
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
precision = abtol (&p, 10);
|
||||
c = *p;
|
||||
}
|
||||
else if (c == '*')
|
||||
{
|
||||
precision = va_arg (ap, long);
|
||||
c = *++p;
|
||||
}
|
||||
}
|
||||
if (c == 'l')
|
||||
c = *++p;
|
||||
if (c == 'l')
|
||||
c = *++p;
|
||||
if (c == 'l')
|
||||
{
|
||||
eputs ("vsnprintf: skipping second: l\n");
|
||||
c = *++p;
|
||||
}
|
||||
switch (c)
|
||||
{
|
||||
case '%':
|
||||
{
|
||||
if (count < size)
|
||||
*str++ = *p;
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
case 'c':
|
||||
{
|
||||
c = va_arg (ap, long);
|
||||
if (count < size)
|
||||
*str++ = c;
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'o':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'X':
|
||||
{
|
||||
long d = va_arg (ap, long);
|
||||
int base = c == 'o' ? 8 : c == 'x' || c == 'X' ? 16 : 10;
|
||||
char *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X');
|
||||
if (c == 'X')
|
||||
strupr (s);
|
||||
int length = strlen (s);
|
||||
if (precision == -1)
|
||||
precision = length;
|
||||
if (!left_p)
|
||||
{
|
||||
while (width-- > precision)
|
||||
{
|
||||
if (count < size)
|
||||
*str++ = pad;
|
||||
count++;
|
||||
}
|
||||
while (precision > length)
|
||||
{
|
||||
if (count < size)
|
||||
*str++ = '0';
|
||||
precision--;
|
||||
width--;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
while (*s)
|
||||
{
|
||||
if (precision-- <= 0)
|
||||
break;
|
||||
width--;
|
||||
c = *s++;
|
||||
if (count < size)
|
||||
*str++ = c;
|
||||
count++;
|
||||
}
|
||||
while (width > 0)
|
||||
{
|
||||
width--;
|
||||
if (count < size)
|
||||
*str++ = pad;
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 's':
|
||||
{
|
||||
char *s = va_arg (ap, char *);
|
||||
int length = s ? strlen (s) : 0;
|
||||
if (precision == -1)
|
||||
precision = length;
|
||||
if (!left_p)
|
||||
{
|
||||
while (width-- > precision)
|
||||
{
|
||||
if (count < size)
|
||||
*str++ = pad;
|
||||
count++;
|
||||
}
|
||||
while (width > length)
|
||||
{
|
||||
if (count < size)
|
||||
*str++ = ' ';
|
||||
precision--;
|
||||
width--;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
while (s && *s)
|
||||
{
|
||||
if (precision-- <= 0)
|
||||
break;
|
||||
width--;
|
||||
c = *s++;
|
||||
if (count < size)
|
||||
*str++ = c;
|
||||
count++;
|
||||
}
|
||||
while (width > 0)
|
||||
{
|
||||
width--;
|
||||
if (count < size)
|
||||
*str++ = pad;
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'f':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
{
|
||||
double d = va_arg8 (ap, double);
|
||||
char *s = dtoab (d, 10, 1);
|
||||
if (c == 'E' || c == 'G')
|
||||
strupr (s);
|
||||
int length = strlen (s);
|
||||
if (precision == -1)
|
||||
precision = length;
|
||||
if (!left_p)
|
||||
{
|
||||
while (width-- > precision)
|
||||
{
|
||||
if (count < size)
|
||||
*str++ = pad;
|
||||
count++;
|
||||
}
|
||||
while (precision > length)
|
||||
{
|
||||
if (count < size)
|
||||
*str++ = ' ';
|
||||
precision--;
|
||||
width--;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
while (*s)
|
||||
{
|
||||
if (precision-- <= 0)
|
||||
break;
|
||||
width--;
|
||||
c = *s++;
|
||||
if (count < size)
|
||||
*str++ = c;
|
||||
count++;
|
||||
}
|
||||
while (width > 0)
|
||||
{
|
||||
width--;
|
||||
if (count < size)
|
||||
*str++ = pad;
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'n':
|
||||
{
|
||||
int *n = va_arg (ap, int *);
|
||||
*n = count;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
eputs ("vsnprintf: not supported: %:");
|
||||
eputc (c);
|
||||
eputs ("\n");
|
||||
p++;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
va_end (ap);
|
||||
if (count < size)
|
||||
*str = 0;
|
||||
return count;
|
||||
}
|
||||
28
sysa/mes-0.22/lib/stdio/vsprintf.c
Normal file
28
sysa/mes-0.22/lib/stdio/vsprintf.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* -*-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 <limits.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int
|
||||
vsprintf (char *str, char const *format, va_list ap)
|
||||
{
|
||||
return vsnprintf (str, LONG_MAX, format, ap);
|
||||
}
|
||||
93
sysa/mes-0.22/lib/stdio/vsscanf.c
Normal file
93
sysa/mes-0.22/lib/stdio/vsscanf.c
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/* -*-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 <mes/lib.h>
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
vsscanf (char const *s, char const *template, va_list ap)
|
||||
{
|
||||
char *p = (char *) s;
|
||||
char const *t = template;
|
||||
int count = 0;
|
||||
while (*t && *p)
|
||||
if (*t != '%')
|
||||
{
|
||||
t++;
|
||||
p++;
|
||||
}
|
||||
else
|
||||
{
|
||||
t++;
|
||||
char c = *t;
|
||||
if (c == 'l')
|
||||
c = *++t;
|
||||
switch (c)
|
||||
{
|
||||
case '%':
|
||||
{
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
case 'c':
|
||||
{
|
||||
char *c = va_arg (ap, char *);
|
||||
*c = *p++;
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'u':
|
||||
{
|
||||
int *d = va_arg (ap, int *);
|
||||
*d = abtol ((char const **)&p, 10);
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
case 'e':
|
||||
case 'f':
|
||||
case 'g':
|
||||
case 'E':
|
||||
case 'G':
|
||||
{
|
||||
float *f = va_arg (ap, float *);
|
||||
*f = strtod (p, &p);
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
eputs ("vsscanf: not supported: %:");
|
||||
eputc (c);
|
||||
eputs ("\n");
|
||||
t++;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
t++;
|
||||
}
|
||||
va_end (ap);
|
||||
return count;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue