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/>.
28 return c >= '0' && c <= '9';
34 return isdigit (c) || c >= 'a' && c <= 'f';
40 return (c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r' || c == ' ');
44 isnumber (int c, int base)
47 return (c >= '0') && (c <= '1');
49 return (c >= '0') && (c <= '7');
57 abtoi (char const **p, int base)
68 while (isnumber (*s, base))
71 int m = *s > '9' ? 'a' - 10 : '0';
89 static char itoa_buf[12];
90 char *p = itoa_buf + 11;
103 *p-- = '0' + (u % 10);
107 if (sign && *(p + 1) != '0')
114 itoab (int x, int base)
116 static char itoa_buf[12];
117 char *p = itoa_buf + 11;
131 *p-- = i > 9 ? 'a' + i - 10 : '0' + i;
135 if (sign && *(p + 1) != '0')
141 int _ungetc_pos = -1;
142 char _ungetc_buf[10];
149 if (_ungetc_pos == -1)
151 int r = read (fd, &c, 1);
158 i = _ungetc_buf[_ungetc_pos];
168 fdputc (int c, int fd)
170 write (fd, (char*)&c, 1);
175 fdputs (char const* s, int fd)
183 fdungetc (int c, int fd)
186 _ungetc_buf[_ungetc_pos] = c;
193 eputs (char const* s)
196 write (STDERR, s, i);
204 return fdputc (c, STDERR);