| 1 |
/* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */ |
| 2 |
/* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */ |
| 3 |
|
| 4 |
/* |
| 5 |
* write_list.d - ugly printer for lists |
| 6 |
* |
| 7 |
* Copyright (c) 1984 Taiichi Yuasa and Masami Hagiya |
| 8 |
* Copyright (c) 1990 Giuseppe Attardi |
| 9 |
* Copyright (c) 2001 Juan Jose Garcia Ripoll |
| 10 |
* |
| 11 |
* See file 'LICENSE' for the copyright details. |
| 12 |
* |
| 13 |
*/ |
| 14 |
|
| 15 |
#include <ecl/ecl.h> |
| 16 |
#include <ecl/internal.h> |
| 17 |
|
| 18 |
void |
| 19 |
_ecl_write_list(cl_object x, cl_object stream) |
| 20 |
{ |
| 21 |
const cl_env_ptr env = ecl_process_env(); |
| 22 |
bool circle; |
| 23 |
cl_fixnum print_level, print_length; |
| 24 |
cl_index i; |
| 25 |
cl_object y; |
| 26 |
if (Null(x)) { |
| 27 |
_ecl_write_symbol(x, stream); |
| 28 |
return; |
| 29 |
} |
| 30 |
circle = ecl_print_circle(); |
| 31 |
if (ecl_print_readably()) { |
| 32 |
print_level = MOST_POSITIVE_FIXNUM; |
| 33 |
print_length = MOST_POSITIVE_FIXNUM; |
| 34 |
} else { |
| 35 |
print_level = ecl_print_level(); |
| 36 |
print_length = ecl_print_length(); |
| 37 |
} |
| 38 |
if (print_level == 0) { |
| 39 |
ecl_write_char('#', stream); |
| 40 |
return; |
| 41 |
} |
| 42 |
ecl_bds_bind(env, @'*print-level*', ecl_make_fixnum(print_level-1)); |
| 43 |
ecl_write_char('(', stream); |
| 44 |
for (i = 0; ; i++) { |
| 45 |
if (i >= print_length) { |
| 46 |
writestr_stream("...", stream); |
| 47 |
break; |
| 48 |
} |
| 49 |
y = CAR(x); |
| 50 |
x = CDR(x); |
| 51 |
si_write_object(y, stream); |
| 52 |
/* FIXME! */ |
| 53 |
if (x == OBJNULL || ECL_ATOM(x) || |
| 54 |
(circle && _ecl_will_print_as_hash(x))) |
| 55 |
{ |
| 56 |
if (x != ECL_NIL) { |
| 57 |
ecl_write_char(' ', stream); |
| 58 |
writestr_stream(". ", stream); |
| 59 |
si_write_object(x, stream); |
| 60 |
} |
| 61 |
break; |
| 62 |
} |
| 63 |
if (i == 0 && y != OBJNULL && ecl_t_of(y) == t_symbol) |
| 64 |
ecl_write_char(' ', stream); |
| 65 |
else |
| 66 |
ecl_write_char(' ', stream); |
| 67 |
} |
| 68 |
ecl_write_char(')', stream); |
| 69 |
ecl_bds_unwind1(env); |
| 70 |
} |