1 /* -*-comment-start: "//";comment-end:""-*-
2 * Mes --- Maxwell Equations of Software
3 * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5 * This file is part of Mes.
7 * Mes is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or (at
10 * your option) any later version.
12 * Mes is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Mes. If not, see <http://www.gnu.org/licenses/>.
26 return c >= '0' && c <= '9';
32 return isdigit (c) || c >= 'a' && c <= 'f';
38 return (c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r' || c == ' ');
42 isnumber (int c, int base)
45 return (c >= '0') && (c <= '1');
47 return (c >= '0') && (c <= '7');
55 abtoi (char const **p, int base)
66 while (isnumber (*s, base))
69 int m = *s > '9' ? 'a' - 10 : '0';
87 static char itoa_buf[12];
88 char *p = itoa_buf + 11;
101 *p-- = '0' + (u % 10);
105 if (sign && *(p + 1) != '0')
112 itoab (int x, int base)
114 static char itoa_buf[12];
115 char *p = itoa_buf + 11;
129 *p-- = i > 9 ? 'a' + i - 10 : '0' + i;
133 if (sign && *(p + 1) != '0')
139 int _ungetc_pos = -1;
140 char _ungetc_buf[10];
147 if (_ungetc_pos == -1)
149 int r = read (fd, &c, 1);
156 i = _ungetc_buf[_ungetc_pos];
166 fdputc (int c, int fd)
168 write (fd, (char*)&c, 1);
175 write (STDOUT, (char*)&c, 1);
180 fdputs (char const* s, int fd)
188 fdungetc (int c, int fd)
191 _ungetc_buf[_ungetc_pos] = c;
198 return fdgetc (g_stdin);