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';
87 number_to_ascii (int x, int base, int signed_p)
89 static char itoa_buf[12];
90 char *p = itoa_buf + 11;
95 if (signed_p && x < 0)
104 *p-- = i > 9 ? 'a' + i - 10 : '0' + i;
108 if (sign && *(p + 1) != '0')
115 itoab (int x, int base)
117 return number_to_ascii (x, base, 1);
123 return number_to_ascii (x, 10, 1);
129 return number_to_ascii (x, 10, 0);
132 int _ungetc_pos = -1;
133 char _ungetc_buf[10];
140 if (_ungetc_pos == -1)
142 int r = read (fd, &c, 1);
149 i = _ungetc_buf[_ungetc_pos];
159 fdputc (int c, int fd)
161 write (fd, (char*)&c, 1);
166 fdputs (char const* s, int fd)
174 fdungetc (int c, int fd)
177 _ungetc_buf[_ungetc_pos] = c;
181 #if POSIX || __x86_64__
184 eputs (char const* s)
187 write (STDERR, s, i);
195 return fdputc (c, STDERR);