1 /* -*-comment-start: "//";comment-end:""-*-
2 * Mes --- Maxwell Equations of Software
3 * Copyright © 2016,2017 Jan 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/>.
27 return ungetc (c, g_stdin);
41 return MAKE_NUMBER (peekchar ());
47 return MAKE_NUMBER (getchar ());
53 ungetchar (VALUE (i));
58 write_byte (SCM x) ///((arity . n))
63 if (TYPE (p) == TPAIR && TYPE (car (p)) == TNUMBER && VALUE (CAR (p)) != 1)
66 write (fd, (char*)&cc, 1);
68 assert (TYPE (c) == TNUMBER || TYPE (c) == TCHAR);
73 char string_to_cstring_buf[1024];
75 string_to_cstring (SCM s)
77 //static char buf[1024];
79 char *p = string_to_cstring_buf;
83 *p++ = VALUE (car (s));
88 return string_to_cstring_buf;
92 getenv_ (SCM s) ///((name . "getenv"))
95 p = getenv (string_to_cstring (s));
96 return p ? MAKE_STRING (cstring_to_list (p)) : cell_f;
100 access_p (SCM file_name, SCM mode)
102 return access (string_to_cstring (file_name), VALUE (mode)) == 0 ? cell_t : cell_f;
106 current_input_port ()
108 return MAKE_NUMBER (g_stdin);
112 open_input_file (SCM file_name)
114 return MAKE_NUMBER (open (string_to_cstring (file_name), O_RDONLY));
118 set_current_input_port (SCM port)
120 g_stdin = VALUE (port) ? VALUE (port) : STDIN;
121 return current_input_port ();
125 current_output_port ()
127 return MAKE_NUMBER (g_stdout);
131 open_output_file (SCM x) ///((arity . n))
133 SCM file_name = car (x);
135 int mode = S_IRUSR|S_IWUSR;
136 if (TYPE (x) == TPAIR && TYPE (car (x)) == TNUMBER) mode = VALUE (car (x));
137 return MAKE_NUMBER (open (string_to_cstring (file_name), O_WRONLY|O_CREAT|O_TRUNC,mode));
141 set_current_output_port (SCM port)
143 g_stdout = VALUE (port) ? VALUE (port) : STDOUT;
144 return current_output_port ();
148 force_output (SCM p) ///((arity . n))
150 return cell_unspecified;