#line 1 "/build/ecl/src/ecl-26.3.27/src/c/print.d"
/* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */

/*
 * print.d - print
 *
 * Copyright (c) 1984 Taiichi Yuasa and Masami Hagiya
 * Copyright (c) 1990 Giuseppe Attardi
 * Copyright (c) 2001 Juan Jose Garcia Ripoll
 *
 * See file 'LICENSE' for the copyright 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*",69));
  else if (stream == ECL_T)
    return ecl_symbol_value(ECL_SYM("*TERMINAL-IO*",70));
  return stream;
}

int
ecl_print_base(void)
{
  const cl_env_ptr the_env = ecl_process_env();
  cl_object object = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-BASE*",47));
  cl_fixnum base;
  unlikely_if (!ECL_FIXNUMP(object) || (base = ecl_fixnum(object)) < 2 || base > 36) {
    ECL_SETQ(the_env, ECL_SYM("*PRINT-BASE*",47), 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)
{
  const cl_env_ptr the_env = ecl_process_env();
  cl_object object = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-LEVEL*",53));
  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(the_env, ECL_SYM("*PRINT-LEVEL*",53), 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)
{
  const cl_env_ptr the_env = ecl_process_env();
  cl_object object = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-LENGTH*",52));
  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(the_env, ECL_SYM("*PRINT-LENGTH*",52), 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*",58)) != ECL_NIL;
}

cl_object
ecl_print_case(void)
{
  const cl_env_ptr the_env = ecl_process_env();
  cl_object output = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-CASE*",48));
  unlikely_if (output != ECL_SYM(":UPCASE",1360) &&
               output != ECL_SYM(":DOWNCASE",1254) &&
               output != ECL_SYM(":CAPITALIZE",1233))
    {
      ECL_SETQ(the_env, ECL_SYM("*PRINT-CASE*",48), ECL_SYM(":DOWNCASE",1254));
      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*",51)) != ECL_NIL;
}

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

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

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

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

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

  #line 162
#if defined(__clang__) || defined(__GNUC__)
	__attribute__((unused)) const cl_env_ptr the_env = ecl_process_env();
#else
	const cl_env_ptr the_env = ecl_process_env();
#endif
#line 162
	static cl_object KEYS[16] = {(cl_object)(cl_symbols+1350), (cl_object)(cl_symbols+1229), (cl_object)(cl_symbols+1231), (cl_object)(cl_symbols+1235), (cl_object)(cl_symbols+1236), (cl_object)(cl_symbols+1261), (cl_object)(cl_symbols+1274), (cl_object)(cl_symbols+1298), (cl_object)(cl_symbols+1299), (cl_object)(cl_symbols+1300), (cl_object)(cl_symbols+1308), (cl_object)(cl_symbols+1323), (cl_object)(cl_symbols+1326), (cl_object)(cl_symbols+1332), (cl_object)(cl_symbols+1333), (cl_object)(cl_symbols+1340)};
	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 162
	cl_object KEY_VARS[32];
#line 162
	ecl_va_list ARGS;
	ecl_va_start(ARGS, x, narg, 1);
#line 162
	if (ecl_unlikely(narg < 1)) FEwrong_num_arguments(ecl_make_fixnum(921));
#line 162
	cl_parse_key(ARGS, 16, KEYS, KEY_VARS, NULL, 0);
#line 162
	if (KEY_VARS[16]==ECL_NIL) {
#line 162
	  strm = ECL_NIL;
	} else {
#line 162
	  strm = KEY_VARS[0];
	}
#line 162
	if (KEY_VARS[17]==ECL_NIL) {
#line 162
	  array = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-ARRAY*",46));
	} else {
#line 162
	  array = KEY_VARS[1];
	}
#line 162
	if (KEY_VARS[18]==ECL_NIL) {
#line 162
	  base = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-BASE*",47));
	} else {
#line 162
	  base = KEY_VARS[2];
	}
#line 162
	if (KEY_VARS[19]==ECL_NIL) {
#line 162
	  cas = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-CASE*",48));
	} else {
#line 162
	  cas = KEY_VARS[3];
	}
#line 162
	if (KEY_VARS[20]==ECL_NIL) {
#line 162
	  circle = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-CIRCLE*",49));
	} else {
#line 162
	  circle = KEY_VARS[4];
	}
#line 162
	if (KEY_VARS[21]==ECL_NIL) {
#line 162
	  escape = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-ESCAPE*",50));
	} else {
#line 162
	  escape = KEY_VARS[5];
	}
#line 162
	if (KEY_VARS[22]==ECL_NIL) {
#line 162
	  gensym = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-GENSYM*",51));
	} else {
#line 162
	  gensym = KEY_VARS[6];
	}
#line 162
	if (KEY_VARS[23]==ECL_NIL) {
#line 162
	  length = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-LENGTH*",52));
	} else {
#line 162
	  length = KEY_VARS[7];
	}
#line 162
	if (KEY_VARS[24]==ECL_NIL) {
#line 162
	  level = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-LEVEL*",53));
	} else {
#line 162
	  level = KEY_VARS[8];
	}
#line 162
	if (KEY_VARS[25]==ECL_NIL) {
#line 162
	  lines = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-LINES*",54));
	} else {
#line 162
	  lines = KEY_VARS[9];
	}
#line 162
	if (KEY_VARS[26]==ECL_NIL) {
#line 162
	  miser_width = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-MISER-WIDTH*",55));
	} else {
#line 162
	  miser_width = KEY_VARS[10];
	}
#line 162
	if (KEY_VARS[27]==ECL_NIL) {
#line 162
	  pprint_dispatch = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-PPRINT-DISPATCH*",56));
	} else {
#line 162
	  pprint_dispatch = KEY_VARS[11];
	}
#line 162
	if (KEY_VARS[28]==ECL_NIL) {
#line 162
	  pretty = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-PRETTY*",57));
	} else {
#line 162
	  pretty = KEY_VARS[12];
	}
#line 162
	if (KEY_VARS[29]==ECL_NIL) {
#line 162
	  radix = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-RADIX*",58));
	} else {
#line 162
	  radix = KEY_VARS[13];
	}
#line 162
	if (KEY_VARS[30]==ECL_NIL) {
#line 162
	  readably = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-READABLY*",59));
	} else {
#line 162
	  readably = KEY_VARS[14];
	}
#line 162
	if (KEY_VARS[31]==ECL_NIL) {
#line 162
	  right_margin = ecl_cmp_symbol_value(the_env, ECL_SYM("*PRINT-RIGHT-MARGIN*",60));
	} else {
#line 162
	  right_margin = KEY_VARS[15];
	}
#line 162
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-ARRAY*",46), array);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-BASE*",47), base);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-CASE*",48), cas);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-CIRCLE*",49), circle);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-ESCAPE*",50), escape);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-GENSYM*",51), gensym);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-LEVEL*",53), level);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-LENGTH*",52), length);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-LINES*",54), lines);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-MISER-WIDTH*",55), miser_width);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-PPRINT-DISPATCH*",56), pprint_dispatch);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-PRETTY*",57), pretty);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-RADIX*",58), radix);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-READABLY*",59), readably);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-RIGHT-MARGIN*",60), 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
	the_env->values[0] = __value0;
#line 183
	ecl_va_end(ARGS);
#line 183
	return __value0;
#line 183
}
;
  }

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

  #line 188
#if defined(__clang__) || defined(__GNUC__)
	__attribute__((unused)) const cl_env_ptr the_env = ecl_process_env();
#else
	const cl_env_ptr the_env = ecl_process_env();
#endif
#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(661));
#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
	the_env->values[0] = __value0;
#line 189
	va_end(ARGS);
#line 189
	return __value0;
#line 189
}
;
  }

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

  #line 194
#if defined(__clang__) || defined(__GNUC__)
	__attribute__((unused)) const cl_env_ptr the_env = ecl_process_env();
#else
	const cl_env_ptr the_env = ecl_process_env();
#endif
#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(665));
#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
	the_env->values[0] = __value0;
#line 195
	va_end(ARGS);
#line 195
	return __value0;
#line 195
}
;
  }

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

  #line 200
#if defined(__clang__) || defined(__GNUC__)
	__attribute__((unused)) const cl_env_ptr the_env = ecl_process_env();
#else
	const cl_env_ptr the_env = ecl_process_env();
#endif
#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(650));
#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*",50), ECL_T);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-PRETTY*",57), 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
#if defined(__clang__) || defined(__GNUC__)
	__attribute__((unused)) const cl_env_ptr the_env = ecl_process_env();
#else
	const cl_env_ptr the_env = ecl_process_env();
#endif
#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(663));
#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
	the_env->values[0] = __value0;
#line 213
	va_end(ARGS);
#line 213
	return __value0;
#line 213
}
;
  }

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

  #line 218
#if defined(__clang__) || defined(__GNUC__)
	__attribute__((unused)) const cl_env_ptr the_env = ecl_process_env();
#else
	const cl_env_ptr the_env = ecl_process_env();
#endif
#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(923));
#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
	the_env->values[0] = __value0;
#line 221
	va_end(ARGS);
#line 221
	return __value0;
#line 221
}
;
  }

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

  #line 226
#if defined(__clang__) || defined(__GNUC__)
	__attribute__((unused)) const cl_env_ptr the_env = ecl_process_env();
#else
	const cl_env_ptr the_env = ecl_process_env();
#endif
#line 226
	cl_object strm;
#line 226
	static cl_object KEYS[2] = {(cl_object)(cl_symbols+1347), (cl_object)(cl_symbols+1256)};
	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(926));
#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*/926), 1, strng, ecl_make_fixnum(/*STRING*/808));
  strm = _ecl_stream_or_default_output(strm);
  /* Optimization: directly call stream-write-string for CLOS streams */
#ifdef ECL_CLOS_STREAMS
  if (!ECL_ANSI_STREAM_P(strm))
    _ecl_funcall5(ECL_SYM("GRAY::STREAM-WRITE-STRING",1723), strm, strng, start, end);
  else
#endif
    si_do_write_sequence(strng, strm, start, end);
  {
#line 236
	#line 236
	cl_object __value0 = strng;
#line 236
	the_env->nvalues = 1;
#line 236
	the_env->values[0] = __value0;
#line 236
	ecl_va_end(ARGS);
#line 236
	return __value0;
#line 236
}
;
  }

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

  #line 241
#if defined(__clang__) || defined(__GNUC__)
	__attribute__((unused)) const cl_env_ptr the_env = ecl_process_env();
#else
	const cl_env_ptr the_env = ecl_process_env();
#endif
#line 241
	cl_object strm;
#line 241
	static cl_object KEYS[2] = {(cl_object)(cl_symbols+1347), (cl_object)(cl_symbols+1256)};
	cl_object start;
	cl_object end;
#line 241
	cl_object KEY_VARS[4];
#line 241
	ecl_va_list ARGS;
	ecl_va_start(ARGS, strng, narg, 1);
#line 241
	if (ecl_unlikely(narg < 1)) FEwrong_num_arguments(ecl_make_fixnum(924));
#line 241
	if (narg > 1) {
#line 241
		strm = ecl_va_arg(ARGS);
#line 241
	} else {
#line 241
		strm = ECL_NIL;
#line 241
	}
#line 241
	cl_parse_key(ARGS, 2, KEYS, KEY_VARS, NULL, 0);
#line 241
	if (KEY_VARS[2]==ECL_NIL) {
#line 241
	  start = ecl_make_fixnum(0);
	} else {
#line 241
	  start = KEY_VARS[0];
	}
#line 241
	if (KEY_VARS[3]==ECL_NIL) {
#line 241
	  end = ECL_NIL;
	} else {
#line 241
	  end = KEY_VARS[1];
	}
#line 241
  unlikely_if (!ECL_STRINGP(strng))
    FEwrong_type_nth_arg(ecl_make_fixnum(/*WRITE-LINE*/924), 1, strng, ecl_make_fixnum(/*STRING*/808));
  strm = _ecl_stream_or_default_output(strm);
  /* Optimization: directly call stream-write-string for CLOS streams */
#ifdef ECL_CLOS_STREAMS
  if (!ECL_ANSI_STREAM_P(strm))
    _ecl_funcall5(ECL_SYM("GRAY::STREAM-WRITE-STRING",1723), strm, strng,
                  start, end);
  else
#endif
    si_do_write_sequence(strng, strm, start, end);
  ecl_terpri(strm);
  {
#line 253
	#line 253
	cl_object __value0 = strng;
#line 253
	the_env->nvalues = 1;
#line 253
	the_env->values[0] = __value0;
#line 253
	ecl_va_end(ARGS);
#line 253
	return __value0;
#line 253
}
;
  }

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

  #line 258
#if defined(__clang__) || defined(__GNUC__)
	__attribute__((unused)) const cl_env_ptr the_env = ecl_process_env();
#else
	const cl_env_ptr the_env = ecl_process_env();
#endif
#line 258
	cl_object strm;
#line 258
	va_list ARGS;
	va_start(ARGS, narg);
#line 258
	if (ecl_unlikely(narg < 0|| narg > 1)) FEwrong_num_arguments(ecl_make_fixnum(858));
#line 258
	if (narg > 0) {
#line 258
		strm = va_arg(ARGS,cl_object);
#line 258
	} else {
#line 258
		strm = ECL_NIL;
#line 258
	}
#line 258
  ecl_terpri(strm);
  {
#line 259
	#line 259
	cl_object __value0 = ECL_NIL;
#line 259
	the_env->nvalues = 1;
#line 259
	the_env->values[0] = __value0;
#line 259
	va_end(ARGS);
#line 259
	return __value0;
#line 259
}
;
  }

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

  #line 264
#if defined(__clang__) || defined(__GNUC__)
	__attribute__((unused)) const cl_env_ptr the_env = ecl_process_env();
#else
	const cl_env_ptr the_env = ecl_process_env();
#endif
#line 264
	cl_object strm;
#line 264
	va_list ARGS;
	va_start(ARGS, narg);
#line 264
	if (ecl_unlikely(narg < 0|| narg > 1)) FEwrong_num_arguments(ecl_make_fixnum(392));
#line 264
	if (narg > 0) {
#line 264
		strm = va_arg(ARGS,cl_object);
#line 264
	} else {
#line 264
		strm = ECL_NIL;
#line 264
	}
#line 264
  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",1704), strm);
  }
#endif
  if (ecl_file_column(strm) == 0) {
    {
#line 271
	#line 271
	cl_object __value0 = ECL_NIL;
#line 271
	the_env->nvalues = 1;
#line 271
	the_env->values[0] = __value0;
#line 271
	va_end(ARGS);
#line 271
	return __value0;
#line 271
}
;
  }
  ecl_write_char('\n', strm);
  ecl_force_output(strm);
  {
#line 275
	#line 275
	cl_object __value0 = ECL_T;
#line 275
	the_env->nvalues = 1;
#line 275
	the_env->values[0] = __value0;
#line 275
	va_end(ARGS);
#line 275
	return __value0;
#line 275
}
;
  }

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

  #line 280
#if defined(__clang__) || defined(__GNUC__)
	__attribute__((unused)) const cl_env_ptr the_env = ecl_process_env();
#else
	const cl_env_ptr the_env = ecl_process_env();
#endif
#line 280
	cl_object strm;
#line 280
	va_list ARGS;
	va_start(ARGS, narg);
#line 280
	if (ecl_unlikely(narg < 0|| narg > 1)) FEwrong_num_arguments(ecl_make_fixnum(372));
#line 280
	if (narg > 0) {
#line 280
		strm = va_arg(ARGS,cl_object);
#line 280
	} else {
#line 280
		strm = ECL_NIL;
#line 280
	}
#line 280
  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",1702), strm);
  }
#endif
  ecl_finish_output(strm);
  {
#line 287
	#line 287
	cl_object __value0 = ECL_NIL;
#line 287
	the_env->nvalues = 1;
#line 287
	the_env->values[0] = __value0;
#line 287
	va_end(ARGS);
#line 287
	return __value0;
#line 287
}
;
  }

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

  #line 292
#if defined(__clang__) || defined(__GNUC__)
	__attribute__((unused)) const cl_env_ptr the_env = ecl_process_env();
#else
	const cl_env_ptr the_env = ecl_process_env();
#endif
#line 292
	cl_object strm;
#line 292
	va_list ARGS;
	va_start(ARGS, narg);
#line 292
	if (ecl_unlikely(narg < 0|| narg > 1)) FEwrong_num_arguments(ecl_make_fixnum(388));
#line 292
	if (narg > 0) {
#line 292
		strm = va_arg(ARGS,cl_object);
#line 292
	} else {
#line 292
		strm = ECL_NIL;
#line 292
	}
#line 292
  strm = _ecl_stream_or_default_output(strm);
  ecl_force_output(strm);
  {
#line 294
	#line 294
	cl_object __value0 = ECL_NIL;
#line 294
	the_env->nvalues = 1;
#line 294
	the_env->values[0] = __value0;
#line 294
	va_end(ARGS);
#line 294
	return __value0;
#line 294
}
;
  }

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

  #line 299
#if defined(__clang__) || defined(__GNUC__)
	__attribute__((unused)) const cl_env_ptr the_env = ecl_process_env();
#else
	const cl_env_ptr the_env = ecl_process_env();
#endif
#line 299
	cl_object strm;
#line 299
	va_list ARGS;
	va_start(ARGS, narg);
#line 299
	if (ecl_unlikely(narg < 0|| narg > 1)) FEwrong_num_arguments(ecl_make_fixnum(229));
#line 299
	if (narg > 0) {
#line 299
		strm = va_arg(ARGS,cl_object);
#line 299
	} else {
#line 299
		strm = ECL_NIL;
#line 299
	}
#line 299
  strm = _ecl_stream_or_default_output(strm);
  ecl_clear_output(strm);
  {
#line 301
	#line 301
	cl_object __value0 = ECL_NIL;
#line 301
	the_env->nvalues = 1;
#line 301
	the_env->values[0] = __value0;
#line 301
	va_end(ARGS);
#line 301
	return __value0;
#line 301
}
;
  }

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

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

  #line 313
#if defined(__clang__) || defined(__GNUC__)
	__attribute__((unused)) const cl_env_ptr the_env = ecl_process_env();
#else
	const cl_env_ptr the_env = ecl_process_env();
#endif
#line 313
	static cl_object KEYS[2] = {(cl_object)(cl_symbols+1347), (cl_object)(cl_symbols+1256)};
	cl_object start;
	cl_object end;
#line 313
	cl_object KEY_VARS[4];
#line 313
	ecl_va_list ARGS;
	ecl_va_start(ARGS, stream, narg, 2);
#line 313
	if (ecl_unlikely(narg < 2)) FEwrong_num_arguments(ecl_make_fixnum(925));
#line 313
	cl_parse_key(ARGS, 2, KEYS, KEY_VARS, NULL, 0);
#line 313
	if (KEY_VARS[2]==ECL_NIL) {
#line 313
	  start = ecl_make_fixnum(0);
	} else {
#line 313
	  start = KEY_VARS[0];
	}
#line 313
	if (KEY_VARS[3]==ECL_NIL) {
#line 313
	  end = ECL_NIL;
	} else {
#line 313
	  end = KEY_VARS[1];
	}
#line 313
#ifdef ECL_CLOS_STREAMS
  if (!ECL_ANSI_STREAM_P(stream)) {
    return _ecl_funcall5(ECL_SYM("GRAY::STREAM-WRITE-SEQUENCE",1722),
                         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*",50), ECL_NIL);
  ecl_bds_bind(the_env, ECL_SYM("*PRINT-READABLY*",59), 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*",50), 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",1717), 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_write_string(2, strng, strm);
  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;
}
