1 /* -*-comment-start: "//";comment-end:""-*-
2 * Mes --- Maxwell Equations of Software
3 * Copyright © 2016 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/>.
26 return getc (g_stdin);
32 return ungetc (c, g_stdin);
44 getenv_ (SCM s) ///((name . "getenv"))
46 char *p = getenv (string_to_cstring (s));
47 return p ? MAKE_STRING (cstring_to_list (p)) : cell_f;
53 return MAKE_NUMBER (peekchar ());
59 return MAKE_NUMBER (getchar ());
65 ungetchar (VALUE (i));
70 write_byte (SCM x) ///((arity . n))
75 if (TYPE (p) == PAIR && TYPE (car (p)) == NUMBER) fd = VALUE (car (p));
76 FILE *f = fd == 1 ? stdout : stderr;
77 assert (TYPE (c) == NUMBER || TYPE (c) == CHAR);
86 if (TYPE (x) == STRING)
87 fprintf (stderr, string_to_cstring (x));
88 else if ((write = assq_ref_cache (cell_symbol_write, r0)) != cell_undefined)
89 apply_env (assq_ref_cache (cell_symbol_display, r0), cons (x, cons (MAKE_NUMBER (2), cell_nil)), r0);
90 else if (TYPE (x) == SPECIAL || TYPE (x) == STRING || TYPE (x) == SYMBOL)
91 fprintf (stderr, string_to_cstring (x));
93 fprintf (stderr, "display: undefined\n");
94 return cell_unspecified;
98 force_output (SCM p) ///((arity . n))
101 if (TYPE (p) == PAIR && TYPE (car (p)) == NUMBER) fd = VALUE (car (p));
102 FILE *f = fd == 1 ? stdout : stderr;
104 return cell_unspecified;
108 open_input_file (SCM file_name)
110 return MAKE_NUMBER (open (string_to_cstring (file_name), O_RDONLY));
114 current_input_port ()
116 return MAKE_NUMBER (fileno (g_stdin));
120 set_current_input_port (SCM port)
122 g_stdin = VALUE (port) ? fdopen (VALUE (port), "r") : stdin;
123 return current_input_port ();