#line 1 "/tmp/pkgbuild/lang/ecl/work/ecl-16.1.2/src/c/print.d"
/* -*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*- */
/* vim: set filetype=c tabstop=8 shiftwidth=4 expandtab: */

/*
    print.d -- Print.
*/
/*
    Copyright (c) 1984, Taiichi Yuasa and Masami Hagiya.
    Copyright (c) 1990, Giuseppe Attardi.
    Copyright (c) 2001, Juan Jose Garcia Ripoll.

    ECL is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    See file '../Copyright' for full details.
*/
#include <stdio.h>
#include <ecl/ecl.h>
#include <ecl/internal.h>

cl_object
_ecl_stream_or_default_output(cl_object stream)
{
        if (Null(stream))
                return ecl_symbol_value(ECL_SYM("*STANDARD-OUTPUT*",67));
        else if (stream == ECL_T)
                return ecl_symbol_value(ECL_SYM("*TERMINAL-IO*",68));
        return stream;
}

int
ecl_print_base(void)
{
        cl_object object = ecl_symbol_value(ECL_SYM("*PRINT-BASE*",45));
        cl_fixnum base;
        unlikely_if (!ECL_FIXNUMP(object) || (base = ecl_fixnum(object)) < 2 || base > 36) {
                ECL_SETQ(ecl_process_env(), ECL_SYM("*PRINT-BASE*",45), ecl_make_fixnum(10));
                FEerror("The value of *PRINT-BASE*~%  ~S~%"
                        "is not of the expected type (INTEGER 2 36)", 1, object);
        }
        return base;
}

cl_fixnum
ecl_print_level(void)
{
        cl_object object = ecl_symbol_value(ECL_SYM("*PRINT-LEVEL*",51));
        cl_fixnum level;
        if (object == ECL_NIL) {
                level = MOST_POSITIVE_FIXNUM;
        } else if (ECL_FIXNUMP(object)) {
                level = ecl_fixnum(object);
                if (level < 0) {
                ERROR:  ECL_SETQ(ecl_process_env(), ECL_SYM("*PRINT-LEVEL*",51), ECL_NIL);
                        FEerror("The value of *PRINT-LEVEL*~%  ~S~%"
                                "is not of the expected type (OR NULL (INTEGER 0 *))",
                                1, object);
                }
        } else if (ecl_unlikely(!ECL_BIGNUMP(object))) {
                goto ERROR;
        } else {
                level = MOST_POSITIVE_FIXNUM;
        }
        return level;
}

cl_fixnum
ecl_print_length(void)
{
        cl_object object = ecl_symbol_value(ECL_SYM("*PRINT-LENGTH*",50));
        cl_fixnum length;
        if (object == ECL_NIL) {
                length = MOST_POSITIVE_FIXNUM;
        } else if (ECL_FIXNUMP(object)) {
                length = ecl_fixnum(object);
                unlikely_if (length < 0) {
                ERROR:  ECL_SETQ(ecl_process_env(), ECL_SYM("*PRINT-LENGTH*",50), ECL_NIL);
                        FEerror("The value of *PRINT-LENGTH*~%  ~S~%"
                                "is not of the expected type (OR NULL (INTEGER 0 *))",
                                1, object);
                }
        } else if (ecl_unlikely(!ECL_BIGNUMP(object))) {
                goto ERROR;
        } else {
                length = MOST_POSITIVE_FIXNUM;
        }
        return length;
}

bool
ecl_print_radix(void)
{
        return ecl_symbol_value(ECL_SYM("*PRINT-RADIX*",56)) != ECL_NIL;
}

cl_object
ecl_print_case(void)
{
        cl_object output = ecl_symbol_value(ECL_SYM("*PRINT-CASE*",46));
        unlikely_if (output != ECL_SYM(":UPCASE",1327) &&
                     output != ECL_SYM(":DOWNCASE",1226) &&
                     output != ECL_SYM(":CAPITALIZE",1206))
        {
                ECL_SETQ(ecl_process_env(), ECL_SYM("*PRINT-CASE*",46), ECL_SYM(":DOWNCASE",1226));
                FEerror("The value of *PRINT-CASE*~%  ~S~%"
                        "is not of the expected type "
                        "(MEMBER :UPCASE :DOWNCASE :CAPITALIZE)", 1, output);
        }
        return output;
}

bool
ecl_print_gensym(void)
{
        return ecl_symbol_value(ECL_SYM("*PRINT-GENSYM*",49)) != ECL_NIL;
}

bool
ecl_print_array(void)
{
        return ecl_symbol_value(ECL_SYM("*PRINT-ARRAY*",44)) != ECL_NIL;
}

bool
ecl_print_readably(void)
{
        return ecl_symbol_value(ECL_SYM("*PRINT-READABLY*",57)) != ECL_NIL;
}

bool
ecl_print_escape(void)
{
        return ecl_symbol_value(ECL_SYM("*PRINT-ESCAPE*",48)) != ECL_NIL;
}

bool
ecl_print_circle(void)
{
        return ecl_symbol_value(ECL_SYM("*PRINT-CIRCLE*",47)) != ECL_NIL;
}

#line 160
cl_object cl_write(cl_narg narg, cl_object x, ...)
{
#line 160

#line 161
	const cl_env_ptr the_env = ecl_process_env();
#line 161
	static cl_object KEYS[16] = {(cl_object)(cl_symbols+1318), (cl_object)(cl_symbols+1202), (cl_object)(cl_symbols+1204), (cl_object)(cl_symbols+1208), (cl_object)(cl_symbols+1209), (cl_object)(cl_symbols+1233), (cl_object)(cl_symbols+1245), (cl_object)(cl_symbols+1268), (cl_object)(cl_symbols+1269), (cl_object)(cl_symbols+1270), (cl_object)(cl_symbols+1277), (cl_object)(cl_symbols+1291), (cl_object)(cl_symbols+1294), (cl_object)(cl_symbols+1300), (cl_object)(cl_symbols+1301), (cl_object)(cl_symbols+1308)};
	cl_object strm;
	cl_object array;
	cl_object base;
	cl_object cas;
	cl_object circle;
	cl_object escape;
	cl_object gensym;
	cl_object length;
	cl_object level;
	cl_object lines;
	cl_object miser_width;
	cl_object pprint_dispatch;
	cl_object pretty;
	cl_object radix;
	cl_object readably;
	cl_object right_margin;
#line 161
	cl_object KEY_VARS[32];
#line 161
	ecl_va_list ARGS;
	ecl_va_start(ARGS, x, narg, 1);
#line 161
	if (ecl_unlikely(narg < 1)) FEwrong_num_arguments(ecl_make_fixnum(917));
#line 161
	cl_parse_key(ARGS, 16, KEYS, KEY_VARS, NULL, 0);
#line 161
	if (KEY_VARS[16]==ECL_NIL) {
#line 161
	  strm = ECL_NIL;
	} else {
#line 161
	  strm = KEY_VARS[0];
	}
#line 161
	if (KEY_VARS[17]==ECL_NIL) {
#line 161
	  array = ecl_symbol_value(ECL_SYM("*PRINT-ARRAY*",44));
	} else {
#line 161
	  array = KEY_VARS[1];
	}
#line 161
	if (KEY_VARS[18]==ECL_NIL) {
#line 161
	  base = ecl_symbol_value(ECL_SYM("*PRINT-BASE*",45));
	} else {
#line 161
	  base = KEY_VARS[2];
	}
#line 161
	if (KEY_VARS[19]==ECL_NIL) {
#line 161
	  cas = ecl_symbol_value(ECL_SYM("*PRINT-CASE*",46));
	} else {
#line 161
	  cas = KEY_VARS[3];
	}
#line 161
	if (KEY_VARS[20]==ECL_NIL) {
#line 161
	  circle = ecl_symbol_value(ECL_SYM("*PRINT-CIRCLE*",47));
	} else {
#line 161
	  circle = KEY_VARS[4];
	}
#line 161
	if (KEY_VARS[21]==ECL_NIL) {
#line 161
	  escape = ecl_symbol_value(ECL_SYM("*PRINT-ESCAPE*",48));
	} else {
#line 161
	  escape = KEY_VARS[5];
	}
#line 161
	if (KEY_VARS[22]==ECL_NIL) {
#line 161
	  gensym = ecl_symbol_value(ECL_SYM("*PRINT-GENSYM*",49));
	} else {
#line 161
	  gensym = KEY_VARS[6];
	}
#line 161
	if (KEY_VARS[23]==ECL_NIL) {
#line 161
	  length = ecl_symbol_value(ECL_SYM("*PRINT-LENGTH*",50));
	} else {
#line 161
	  length = KEY_VARS[7];
	}
#line 161
	if (KEY_VARS[24]==ECL_NIL) {
#line 161
	  level = ecl_symbol_value(ECL_SYM("*PRINT-LEVEL*",51));
	} else {
#line 161
	  level = KEY_VARS[8];
	}
#line 161
	if (KEY_VARS[25]==ECL_NIL) {
#line 161
	  lines = ecl_symbol_value(ECL_SYM("*PRINT-LINES*",52));
	} else {
#line 161
	  lines = KEY_VARS[9];
	}
#line 161
	if (KEY_VARS[26]==ECL_NIL) {
#line 161
	  miser_width = ecl_symbol_value(ECL_SYM("*PRINT-MISER-WIDTH*",53));
	} else {
#line 161
	  miser_width = KEY_VARS[10];
	}
#line 161
	if (KEY_VARS[27]==ECL_NIL) {
#line 161
	  pprint_dispatch = ecl_symbol_value(ECL_SYM("*PRINT-PPRINT-DISPATCH*",54));
	} else {
#line 161
	  pprint_dispatch = KEY_VARS[11];
	}
#line 161
	if (KEY_VARS[28]==ECL_NIL) {
#line 161
	  pretty = ecl_symbol_value(ECL_SYM("*PRINT-PRETTY*",55));
	} else {
#line 161
	  pretty = KEY_VARS[12];
	}
#line 161
	if (KEY_VARS[29]==ECL_NIL) {
#line 161
	  radix = ecl_symbol_value(ECL_SYM("*PRINT-RADIX*",56));
	} else {
#line 161
	  radix = KEY_VARS[13];
	}
#line 161
	if (KEY_VARS[30]==ECL_NIL) {
#line 161
	  readably = ecl_symbol_value(ECL_SYM("*PRINT-READABLY*",57));
	} else {
#line 161
	  readably = KEY_VARS[14];
	}
#line 161
	if (KEY_VARS[31]==ECL_NIL) {
#line 161
	  right_margin = ecl_symbol_value(ECL_SYM("*PRINT-RIGHT-MARGIN*",58));
	} else {
#line 161
	  right_margin = KEY_VARS[15];
	}
#line 161

        ecl_bds_bind(the_env, ECL_SYM("*PRINT-ARRAY*",44), array);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-BASE*",45), base);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-CASE*",46), cas);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-CIRCLE*",47), circle);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-ESCAPE*",48), escape);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-GENSYM*",49), gensym);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-LEVEL*",51), level);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-LENGTH*",50), length);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-LINES*",52), lines);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-MISER-WIDTH*",53), miser_width);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-PPRINT-DISPATCH*",54), pprint_dispatch);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-PRETTY*",55), pretty);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-RADIX*",56), radix);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-READABLY*",57), readably);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-RIGHT-MARGIN*",58), right_margin);

        strm = _ecl_stream_or_default_output(strm);
        si_write_object(x, strm);
        ecl_force_output(strm);

        ecl_bds_unwind_n(the_env, 15);
        {
#line 183
	#line 183
	cl_object __value0 = x;
#line 183
	the_env->nvalues = 1;
#line 183
	return __value0;
#line 183
}

}

#line 186
cl_object cl_prin1(cl_narg narg, cl_object obj, ...)
{
#line 186

#line 188
	const cl_env_ptr the_env = ecl_process_env();
#line 188
	cl_object strm;
#line 188
	va_list ARGS;
	va_start(ARGS, obj);
#line 188
	if (ecl_unlikely(narg < 1|| narg > 2)) FEwrong_num_arguments(ecl_make_fixnum(658));
#line 188
	if (narg > 1) {
#line 188
		strm = va_arg(ARGS,cl_object);
#line 188
	} else {
#line 188
		strm = ECL_NIL;
#line 188
	}
#line 188
        ecl_prin1(obj, strm);
        {
#line 189
	#line 189
	cl_object __value0 = obj;
#line 189
	the_env->nvalues = 1;
#line 189
	return __value0;
#line 189
}

}

#line 192
cl_object cl_print(cl_narg narg, cl_object obj, ...)
{
#line 192

#line 194
	const cl_env_ptr the_env = ecl_process_env();
#line 194
	cl_object strm;
#line 194
	va_list ARGS;
	va_start(ARGS, obj);
#line 194
	if (ecl_unlikely(narg < 1|| narg > 2)) FEwrong_num_arguments(ecl_make_fixnum(662));
#line 194
	if (narg > 1) {
#line 194
		strm = va_arg(ARGS,cl_object);
#line 194
	} else {
#line 194
		strm = ECL_NIL;
#line 194
	}
#line 194
        ecl_print(obj, strm);
        {
#line 195
	#line 195
	cl_object __value0 = obj;
#line 195
	the_env->nvalues = 1;
#line 195
	return __value0;
#line 195
}

}

#line 198
cl_object cl_pprint(cl_narg narg, cl_object obj, ...)
{
#line 198

#line 200
	const cl_env_ptr the_env = ecl_process_env();
#line 200
	cl_object strm;
#line 200
	va_list ARGS;
	va_start(ARGS, obj);
#line 200
	if (ecl_unlikely(narg < 1|| narg > 2)) FEwrong_num_arguments(ecl_make_fixnum(647));
#line 200
	if (narg > 1) {
#line 200
		strm = va_arg(ARGS,cl_object);
#line 200
	} else {
#line 200
		strm = ECL_NIL;
#line 200
	}
#line 200
        strm = _ecl_stream_or_default_output(strm);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-ESCAPE*",48), ECL_T);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-PRETTY*",55), ECL_T);
        ecl_write_char('\n', strm);
        si_write_object(obj, strm);
        ecl_force_output(strm);
        ecl_bds_unwind_n(the_env, 2);
        {
the_env->nvalues = 0; return ECL_NIL;
#line 207
}

}

#line 210
cl_object cl_princ(cl_narg narg, cl_object obj, ...)
{
#line 210

#line 212
	const cl_env_ptr the_env = ecl_process_env();
#line 212
	cl_object strm;
#line 212
	va_list ARGS;
	va_start(ARGS, obj);
#line 212
	if (ecl_unlikely(narg < 1|| narg > 2)) FEwrong_num_arguments(ecl_make_fixnum(660));
#line 212
	if (narg > 1) {
#line 212
		strm = va_arg(ARGS,cl_object);
#line 212
	} else {
#line 212
		strm = ECL_NIL;
#line 212
	}
#line 212
        ecl_princ(obj, strm);
        {
#line 213
	#line 213
	cl_object __value0 = obj;
#line 213
	the_env->nvalues = 1;
#line 213
	return __value0;
#line 213
}

}

#line 216
cl_object cl_write_char(cl_narg narg, cl_object c, ...)
{
#line 216

#line 218
	const cl_env_ptr the_env = ecl_process_env();
#line 218
	cl_object strm;
#line 218
	va_list ARGS;
	va_start(ARGS, c);
#line 218
	if (ecl_unlikely(narg < 1|| narg > 2)) FEwrong_num_arguments(ecl_make_fixnum(919));
#line 218
	if (narg > 1) {
#line 218
		strm = va_arg(ARGS,cl_object);
#line 218
	} else {
#line 218
		strm = ECL_NIL;
#line 218
	}
#line 218
        /* INV: ecl_char_code() checks the type of `c' */
        strm = _ecl_stream_or_default_output(strm);
        c = ECL_CODE_CHAR(ecl_write_char(ecl_char_code(c), strm));
        {
#line 221
	#line 221
	cl_object __value0 = c;
#line 221
	the_env->nvalues = 1;
#line 221
	return __value0;
#line 221
}

}

#line 224
cl_object cl_write_string(cl_narg narg, cl_object strng, ...)
{
#line 224

#line 226
	const cl_env_ptr the_env = ecl_process_env();
#line 226
	cl_object strm;
#line 226
	static cl_object KEYS[2] = {(cl_object)(cl_symbols+1315), (cl_object)(cl_symbols+1228)};
	cl_object start;
	cl_object end;
#line 226
	cl_object KEY_VARS[4];
#line 226
	ecl_va_list ARGS;
	ecl_va_start(ARGS, strng, narg, 1);
#line 226
	if (ecl_unlikely(narg < 1)) FEwrong_num_arguments(ecl_make_fixnum(922));
#line 226
	if (narg > 1) {
#line 226
		strm = ecl_va_arg(ARGS);
#line 226
	} else {
#line 226
		strm = ECL_NIL;
#line 226
	}
#line 226
	cl_parse_key(ARGS, 2, KEYS, KEY_VARS, NULL, 0);
#line 226
	if (KEY_VARS[2]==ECL_NIL) {
#line 226
	  start = ecl_make_fixnum(0);
	} else {
#line 226
	  start = KEY_VARS[0];
	}
#line 226
	if (KEY_VARS[3]==ECL_NIL) {
#line 226
	  end = ECL_NIL;
	} else {
#line 226
	  end = KEY_VARS[1];
	}
#line 226
        unlikely_if (!ECL_STRINGP(strng))
                FEwrong_type_nth_arg(ecl_make_fixnum(/*WRITE-STRING*/922), 1, strng, ecl_make_fixnum(/*STRING*/805));
        strm = _ecl_stream_or_default_output(strm);
#ifdef ECL_CLOS_STREAMS
        if (!ECL_ANSI_STREAM_P(strm))
                _ecl_funcall5(ECL_SYM("GRAY::STREAM-WRITE-STRING",1656), strm, strng, start, end);
        else
#endif
                si_do_write_sequence(strng, strm, start, end);
        {
#line 235
	#line 235
	cl_object __value0 = strng;
#line 235
	the_env->nvalues = 1;
#line 235
	return __value0;
#line 235
}

}

#line 238
cl_object cl_write_line(cl_narg narg, cl_object strng, ...)
{
#line 238

#line 240
	const cl_env_ptr the_env = ecl_process_env();
#line 240
	cl_object strm;
#line 240
	static cl_object KEYS[2] = {(cl_object)(cl_symbols+1315), (cl_object)(cl_symbols+1228)};
	cl_object start;
	cl_object end;
#line 240
	cl_object KEY_VARS[4];
#line 240
	ecl_va_list ARGS;
	ecl_va_start(ARGS, strng, narg, 1);
#line 240
	if (ecl_unlikely(narg < 1)) FEwrong_num_arguments(ecl_make_fixnum(920));
#line 240
	if (narg > 1) {
#line 240
		strm = ecl_va_arg(ARGS);
#line 240
	} else {
#line 240
		strm = ECL_NIL;
#line 240
	}
#line 240
	cl_parse_key(ARGS, 2, KEYS, KEY_VARS, NULL, 0);
#line 240
	if (KEY_VARS[2]==ECL_NIL) {
#line 240
	  start = ecl_make_fixnum(0);
	} else {
#line 240
	  start = KEY_VARS[0];
	}
#line 240
	if (KEY_VARS[3]==ECL_NIL) {
#line 240
	  end = ECL_NIL;
	} else {
#line 240
	  end = KEY_VARS[1];
	}
#line 240
        unlikely_if (!ECL_STRINGP(strng))
                FEwrong_type_nth_arg(ecl_make_fixnum(/*WRITE-LINE*/920), 1, strng, ecl_make_fixnum(/*STRING*/805));
        strm = _ecl_stream_or_default_output(strm);
#ifdef ECL_CLOS_STREAMS
        if (!ECL_ANSI_STREAM_P(strm))
                _ecl_funcall5(ECL_SYM("GRAY::STREAM-WRITE-STRING",1656), strm, strng,
                              start, end);
        else
#endif
                si_do_write_sequence(strng, strm, start, end);
        ecl_terpri(strm);
        {
#line 251
	#line 251
	cl_object __value0 = strng;
#line 251
	the_env->nvalues = 1;
#line 251
	return __value0;
#line 251
}

}

#line 254
cl_object cl_terpri(cl_narg narg, ...)
{
#line 254

#line 256
	const cl_env_ptr the_env = ecl_process_env();
#line 256
	cl_object strm;
#line 256
	va_list ARGS;
	va_start(ARGS, narg);
#line 256
	if (ecl_unlikely(narg < 0|| narg > 1)) FEwrong_num_arguments(ecl_make_fixnum(855));
#line 256
	if (narg > 0) {
#line 256
		strm = va_arg(ARGS,cl_object);
#line 256
	} else {
#line 256
		strm = ECL_NIL;
#line 256
	}
#line 256
        ecl_terpri(strm);
        {
#line 257
	#line 257
	cl_object __value0 = ECL_NIL;
#line 257
	the_env->nvalues = 1;
#line 257
	return __value0;
#line 257
}

}

#line 260
cl_object cl_fresh_line(cl_narg narg, ...)
{
#line 260

#line 262
	const cl_env_ptr the_env = ecl_process_env();
#line 262
	cl_object strm;
#line 262
	va_list ARGS;
	va_start(ARGS, narg);
#line 262
	if (ecl_unlikely(narg < 0|| narg > 1)) FEwrong_num_arguments(ecl_make_fixnum(390));
#line 262
	if (narg > 0) {
#line 262
		strm = va_arg(ARGS,cl_object);
#line 262
	} else {
#line 262
		strm = ECL_NIL;
#line 262
	}
#line 262
        strm = _ecl_stream_or_default_output(strm);
#ifdef ECL_CLOS_STREAMS
        if (!ECL_ANSI_STREAM_P(strm)) {
                return _ecl_funcall2(ECL_SYM("GRAY::STREAM-FRESH-LINE",1640), strm);
        }
#endif
        if (ecl_file_column(strm) == 0)
                {
#line 269
	#line 269
	cl_object __value0 = ECL_NIL;
#line 269
	the_env->nvalues = 1;
#line 269
	return __value0;
#line 269
}

        ecl_write_char('\n', strm);
        ecl_force_output(strm);
        {
#line 272
	#line 272
	cl_object __value0 = ECL_T;
#line 272
	the_env->nvalues = 1;
#line 272
	return __value0;
#line 272
}

}

#line 275
cl_object cl_finish_output(cl_narg narg, ...)
{
#line 275

#line 277
	const cl_env_ptr the_env = ecl_process_env();
#line 277
	cl_object strm;
#line 277
	va_list ARGS;
	va_start(ARGS, narg);
#line 277
	if (ecl_unlikely(narg < 0|| narg > 1)) FEwrong_num_arguments(ecl_make_fixnum(370));
#line 277
	if (narg > 0) {
#line 277
		strm = va_arg(ARGS,cl_object);
#line 277
	} else {
#line 277
		strm = ECL_NIL;
#line 277
	}
#line 277
        strm = _ecl_stream_or_default_output(strm);
#ifdef ECL_CLOS_STREAMS
        if (!ECL_ANSI_STREAM_P(strm)) {
                return _ecl_funcall2(ECL_SYM("GRAY::STREAM-FINISH-OUTPUT",1638), strm);
        }
#endif
        ecl_force_output(strm);
        {
#line 284
	#line 284
	cl_object __value0 = ECL_NIL;
#line 284
	the_env->nvalues = 1;
#line 284
	return __value0;
#line 284
}

}

#line 287
cl_object cl_force_output(cl_narg narg, ...)
{
#line 287

#line 289
	const cl_env_ptr the_env = ecl_process_env();
#line 289
	cl_object strm;
#line 289
	va_list ARGS;
	va_start(ARGS, narg);
#line 289
	if (ecl_unlikely(narg < 0|| narg > 1)) FEwrong_num_arguments(ecl_make_fixnum(386));
#line 289
	if (narg > 0) {
#line 289
		strm = va_arg(ARGS,cl_object);
#line 289
	} else {
#line 289
		strm = ECL_NIL;
#line 289
	}
#line 289
        strm = _ecl_stream_or_default_output(strm);
        ecl_force_output(strm);
        {
#line 291
	#line 291
	cl_object __value0 = ECL_NIL;
#line 291
	the_env->nvalues = 1;
#line 291
	return __value0;
#line 291
}

}

#line 294
cl_object cl_clear_output(cl_narg narg, ...)
{
#line 294

#line 296
	const cl_env_ptr the_env = ecl_process_env();
#line 296
	cl_object strm;
#line 296
	va_list ARGS;
	va_start(ARGS, narg);
#line 296
	if (ecl_unlikely(narg < 0|| narg > 1)) FEwrong_num_arguments(ecl_make_fixnum(227));
#line 296
	if (narg > 0) {
#line 296
		strm = va_arg(ARGS,cl_object);
#line 296
	} else {
#line 296
		strm = ECL_NIL;
#line 296
	}
#line 296
        strm = _ecl_stream_or_default_output(strm);
        ecl_clear_output(strm);
        {
#line 298
	#line 298
	cl_object __value0 = ECL_NIL;
#line 298
	the_env->nvalues = 1;
#line 298
	return __value0;
#line 298
}

}

cl_object
cl_write_byte(cl_object integer, cl_object binary_output_stream)
{
        ecl_write_byte(integer, binary_output_stream);
        {
#line 305
	const cl_env_ptr the_env = ecl_process_env();
#line 305
	#line 305
	cl_object __value0 = integer;
#line 305
	the_env->nvalues = 1;
#line 305
	return __value0;
#line 305
}

}

#line 308
cl_object cl_write_sequence(cl_narg narg, cl_object sequence, cl_object stream, ...)
{
#line 308

#line 310
	const cl_env_ptr the_env = ecl_process_env();
#line 310
	static cl_object KEYS[2] = {(cl_object)(cl_symbols+1315), (cl_object)(cl_symbols+1228)};
	cl_object start;
	cl_object end;
#line 310
	cl_object KEY_VARS[4];
#line 310
	ecl_va_list ARGS;
	ecl_va_start(ARGS, stream, narg, 2);
#line 310
	if (ecl_unlikely(narg < 2)) FEwrong_num_arguments(ecl_make_fixnum(921));
#line 310
	cl_parse_key(ARGS, 2, KEYS, KEY_VARS, NULL, 0);
#line 310
	if (KEY_VARS[2]==ECL_NIL) {
#line 310
	  start = ecl_make_fixnum(0);
	} else {
#line 310
	  start = KEY_VARS[0];
	}
#line 310
	if (KEY_VARS[3]==ECL_NIL) {
#line 310
	  end = ECL_NIL;
	} else {
#line 310
	  end = KEY_VARS[1];
	}
#line 310
#ifdef ECL_CLOS_STREAMS
        if (!ECL_ANSI_STREAM_P(stream)) {
                return _ecl_funcall5(ECL_SYM("GRAY::STREAM-WRITE-SEQUENCE",1655),
                                     stream, sequence, start, end);
        } else
#endif
                return si_do_write_sequence(sequence, stream, start, end);
}

cl_object
ecl_princ(cl_object obj, cl_object strm)
{
        const cl_env_ptr the_env = ecl_process_env();
        strm = _ecl_stream_or_default_output(strm);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-ESCAPE*",48), ECL_NIL);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-READABLY*",57), ECL_NIL);
        si_write_object(obj, strm);
        ecl_bds_unwind_n(the_env, 2);
        return obj;
}

cl_object
ecl_prin1(cl_object obj, cl_object strm)
{
        const cl_env_ptr the_env = ecl_process_env();
        strm = _ecl_stream_or_default_output(strm);
        ecl_bds_bind(the_env, ECL_SYM("*PRINT-ESCAPE*",48), ECL_T);
        si_write_object(obj, strm);
        ecl_force_output(strm);
        ecl_bds_unwind1(the_env);
        return obj;
}

cl_object
ecl_print(cl_object obj, cl_object strm)
{
        strm = _ecl_stream_or_default_output(strm);
        ecl_terpri(strm);
        ecl_prin1(obj, strm);
        ecl_princ_char(' ', strm);
        return obj;
}

cl_object
ecl_terpri(cl_object strm)
{
        strm = _ecl_stream_or_default_output(strm);
#ifdef ECL_CLOS_STREAMS
        if (!ECL_ANSI_STREAM_P(strm)) {
                return _ecl_funcall2(ECL_SYM("GRAY::STREAM-TERPRI",1651), strm);
        }
#endif
        ecl_write_char('\n', strm);
        ecl_force_output(strm);
        return(ECL_NIL);
}

void
ecl_write_string(cl_object strng, cl_object strm)
{
        cl_index i;

        strm = _ecl_stream_or_default_output(strm);
        switch(ecl_t_of(strng)) {
#ifdef ECL_UNICODE
        case t_string:
                for (i = 0;  i < strng->string.fillp;  i++)
                        ecl_write_char(strng->string.self[i], strm);
                break;
#endif
        case t_base_string:
                for (i = 0;  i < strng->base_string.fillp;  i++)
                        ecl_write_char(strng->base_string.self[i], strm);
                break;
        default:
                FEwrong_type_nth_arg(ecl_make_fixnum(/*WRITE-STRING*/922), 1, strng, ecl_make_fixnum(/*STRING*/805));
        }
                
        ecl_force_output(strm);
}

/*
        THE ULTRA-SPECIAL-DINNER-SERVICE OPTIMIZATION
*/
void
ecl_princ_str(const char *s, cl_object strm)
{
        strm = _ecl_stream_or_default_output(strm);
        writestr_stream(s, strm);
}

int
ecl_princ_char(int c, cl_object strm)
{
        strm = _ecl_stream_or_default_output(strm);
        ecl_write_char(c, strm);
        if (c == '\n') {
                ecl_force_output(strm);
        }
        return c;
}
