summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--debug.c12
-rw-r--r--lib.c2
-rw-r--r--match.c72
-rw-r--r--parser.c6
-rw-r--r--parser.l6
-rw-r--r--stream.c77
-rw-r--r--sysif.c40
-rw-r--r--txr.150
8 files changed, 173 insertions, 92 deletions
diff --git a/debug.c b/debug.c
index 487ef2a9..f8673f89 100644
--- a/debug.c
+++ b/debug.c
@@ -81,10 +81,10 @@ static void show_bindings(val env, val stream)
if (nilp(env))
break;
else if (consp(env)) {
- format(stream, lit("~s: ~s\n"), level, env, nao);
+ format(stream, lit("~d: ~s\n"), level, env, nao);
break;
} else if (type(env) == ENV) {
- format(stream, lit("~s: ~s\n"), level, env->e.vbindings, nao);
+ format(stream, lit("~d: ~s\n"), level, env->e.vbindings, nao);
env = env->e.up_env;
} else {
format(stream, lit("invalid environment object: ~s\n"), env, nao);
@@ -116,7 +116,7 @@ val debug(val form, val bindings, val data, val line, val pos, val base)
val input, command;
if (print_form) {
- format(std_debug, lit("stopped at line ~a of ~a\n"),
+ format(std_debug, lit("stopped at line ~d of ~a\n"),
lineno, file, nao);
format(std_debug, lit("form: ~s\n"), form, nao);
format(std_debug, lit("depth: ~s\n"), num(debug_depth), nao);
@@ -139,14 +139,14 @@ val debug(val form, val bindings, val data, val line, val pos, val base)
suffix = sub_str(data, pos, plus(pos, half));
}
- format(std_debug, lit("data (~s:~s):\n~s . ~s\n"),
+ format(std_debug, lit("data (~d:~d):\n~s . ~s\n"),
line, plus(pos, base), prefix, suffix, nao);
} else if (data && length_str_ge(data, num(lim - 2))) {
- format(std_debug, lit("data (~s):\n~s...~s\n"), line,
+ format(std_debug, lit("data (~d):\n~s...~s\n"), line,
sub_str(data, zero, num(lim/2 - 4)),
sub_str(data, num(-(lim/2 - 3)), t), nao);
} else {
- format(std_debug, lit("data (~s):\n~s\n"), line, data, nao);
+ format(std_debug, lit("data (~d):\n~s\n"), line, data, nao);
}
print_data = nil;
}
diff --git a/lib.c b/lib.c
index 745714f9..2771c18d 100644
--- a/lib.c
+++ b/lib.c
@@ -4092,7 +4092,7 @@ val gensym(val prefix)
{
prefix = default_arg(prefix, lit("g"));
loc gs_loc = lookup_var_l(nil, gensym_counter_s);
- val name = format(nil, lit("~a~,04a"), prefix,
+ val name = format(nil, lit("~a~,04d"), prefix,
set(gs_loc, plus(deref(gs_loc), one)), nao);
return make_sym(name);
}
diff --git a/match.c b/match.c
index 8b127a0d..eb46e7cc 100644
--- a/match.c
+++ b/match.c
@@ -461,14 +461,14 @@ static val match_line(match_line_ctx c);
typedef val (*h_match_func)(match_line_ctx *c);
#define LOG_MISMATCH(KIND) \
- debuglf(elem, lit(KIND " mismatch, position ~a (~a:~a)"), \
+ debuglf(elem, lit(KIND " mismatch, position ~a (~a:~d)"), \
plus(c->pos, c->base), c->file, c->data_lineno, nao); \
debuglf(elem, lit(" ~a"), c->dataline, nao); \
if (c_num(c->pos) < 77) \
debuglf(elem, lit(" ~*a^"), c->pos, lit(""), nao)
#define LOG_MATCH(KIND, EXTENT) \
- debuglf(elem, lit(KIND " matched, position ~a-~a (~a:~a)"), \
+ debuglf(elem, lit(KIND " matched, position ~a-~a (~a:~d)"), \
plus(c->pos, c->base), EXTENT, c->file, c->data_lineno, nao); \
debuglf(elem, lit(" ~a"), c->dataline, nao); \
if (c_num(EXTENT) < 77) \
@@ -749,7 +749,7 @@ static val h_skip(match_line_ctx *c)
if (!rest(c->specline)) {
debuglf(elem,
- lit("skip to end of line ~a:~a"), c->file, c->data_lineno, nao);
+ lit("skip to end of line ~a:~d"), c->file, c->data_lineno, nao);
return cons(c->bindings, t);
}
@@ -765,13 +765,13 @@ static val h_skip(match_line_ctx *c)
if (min) {
if (reps_min != cmin) {
debuglf(elem,
- lit("skipped only ~a/~a chars to ~a:~a:~a"),
+ lit("skipped only ~d/~d chars to ~a:~d:~d"),
num(reps_min), num(cmin),
c->file, c->data_lineno, c->pos, nao);
return nil;
}
- debuglf(elem, lit("skipped ~a chars to ~a:~a:~a"),
+ debuglf(elem, lit("skipped ~d chars to ~a:~d:~d"),
num(reps_min), c->file, c->data_lineno, c->pos, nao);
}
@@ -937,7 +937,7 @@ next_coll:
}
if ((times || mintimes) && timescounter < ctimin) {
- debuglf(elem, lit("fewer than ~a iterations collected"),
+ debuglf(elem, lit("fewer than ~d iterations collected"),
num(ctimin), nao);
return nil;
}
@@ -1117,7 +1117,7 @@ static val h_fun(match_line_ctx *c)
val bindings_cp = copy_list(c->bindings);
if (!equal(length(args), length_list(params)))
- sem_error(elem, lit("function ~a takes ~a argument(s)"),
+ sem_error(elem, lit("function ~a takes ~d argument(s)"),
sym, length_list(params), nao);
for (piter = params, aiter = args; piter;
@@ -1213,7 +1213,7 @@ static val h_chr(match_line_ctx *c)
c->bindings = dest_bind(elem, c->bindings, pat, c->pos, eql_f);
if (c->bindings == t) {
- debuglf(elem, lit("chr mismatch (position ~a vs. ~a)"), c->pos, pat, nao);
+ debuglf(elem, lit("chr mismatch (position ~d vs. ~d)"), c->pos, pat, nao);
return nil;
}
@@ -1365,7 +1365,7 @@ static val match_line_completely(match_line_ctx c)
val new_pos = cdr(result);
if (new_pos != t && length_str_gt(c.dataline, minus(new_pos, c.base))) {
- debuglf(c.specline, lit("spec only matches line to position ~a: ~a"),
+ debuglf(c.specline, lit("spec only matches line to position ~d: ~a"),
new_pos, c.dataline, nao);
return nil;
}
@@ -2109,13 +2109,13 @@ static val v_skip(match_files_ctx *c)
if (min) {
if (reps_min != cmin) {
- debuglf(skipspec, lit("skipped only ~a/~a lines to ~a:~a"),
+ debuglf(skipspec, lit("skipped only ~d/~d lines to ~a:~d"),
num(reps_min), num(cmin),
c->curfile, c->data_lineno, nao);
uw_block_return(nil, nil);
}
- debuglf(skipspec, lit("skipped ~a lines to ~a:~a"),
+ debuglf(skipspec, lit("skipped ~d lines to ~a:~d"),
num(reps_min), c->curfile,
c->data_lineno, nao);
}
@@ -2128,19 +2128,19 @@ static val v_skip(match_files_ctx *c)
last_good_result = result;
last_good_line = c->data_lineno;
} else {
- debuglf(skipspec, lit("skip matched ~a:~a"), c->curfile,
+ debuglf(skipspec, lit("skip matched ~a:~d"), c->curfile,
c->data_lineno, nao);
break;
}
} else {
- debuglf(skipspec, lit("skip didn't match ~a:~a"),
+ debuglf(skipspec, lit("skip didn't match ~a:~d"),
c->curfile, c->data_lineno, nao);
}
if (!c->data)
break;
- debuglf(skipspec, lit("skip didn't match ~a:~a"), c->curfile,
+ debuglf(skipspec, lit("skip didn't match ~a:~d"), c->curfile,
c->data_lineno, nao);
c->data = rest(c->data);
@@ -2152,7 +2152,7 @@ static val v_skip(match_files_ctx *c)
if (result)
return result;
if (last_good_result) {
- debuglf(skipspec, lit("greedy skip matched ~a:~a"),
+ debuglf(skipspec, lit("greedy skip matched ~a:~d"),
c->curfile, last_good_line, nao);
return last_good_result;
}
@@ -2191,11 +2191,11 @@ static val v_fuzz(match_files_ctx *c)
val result = match_files(fuzz_ctx);
if (result) {
- debuglf(fuzz_spec, lit("fuzz matched ~a:~a"), c->curfile,
+ debuglf(fuzz_spec, lit("fuzz matched ~a:~d"), c->curfile,
c->data_lineno, nao);
good++;
} else {
- debuglf(fuzz_spec, lit("fuzz didn't match ~a:~a"),
+ debuglf(fuzz_spec, lit("fuzz didn't match ~a:~d"),
c->curfile, c->data_lineno, nao);
}
@@ -2207,14 +2207,14 @@ static val v_fuzz(match_files_ctx *c)
if (!c->spec) {
if (good >= cm)
break;
- debuglf(fuzz_spec, lit("fuzz failed ~a:~a"), c->curfile,
+ debuglf(fuzz_spec, lit("fuzz failed ~a:~d"), c->curfile,
c->data_lineno, nao);
return nil;
}
}
if (reps == cn && good < cm) {
- debuglf(fuzz_spec, lit("fuzz failed ~a:~a"), c->curfile,
+ debuglf(fuzz_spec, lit("fuzz failed ~a:~d"), c->curfile,
c->data_lineno, nao);
return nil;
}
@@ -2720,7 +2720,7 @@ static val v_gather(match_files_ctx *c)
match_files(mf_spec(*c, ul_spec)));
if (success) {
- debuglf(specline, lit("until/last matched ~a:~a"),
+ debuglf(specline, lit("until/last matched ~a:~d"),
c->curfile, c->data_lineno, nao);
/* Until discards bindings and position, last keeps them. */
if (sym == last_s) {
@@ -2742,7 +2742,7 @@ static val v_gather(match_files_ctx *c)
specs = new_specs;
if (consp(max_data)) {
- debuglf(specline, lit("gather advancing from line ~a to ~a"),
+ debuglf(specline, lit("gather advancing from line ~d to ~d"),
c->data_lineno, max_line, nao);
c->data_lineno = max_line;
c->data = max_data;
@@ -2752,7 +2752,7 @@ static val v_gather(match_files_ctx *c)
} else {
c->data_lineno = plus(c->data_lineno, one);
c->data = rest(c->data);
- debuglf(specline, lit("gather advancing by one line to ~a"), c->data_lineno, nao);
+ debuglf(specline, lit("gather advancing by one line to ~d"), c->data_lineno, nao);
}
}
@@ -2855,7 +2855,7 @@ static val v_collect(match_files_ctx *c)
match_files(mf_spec_bindings(*c, ul_spec, new_bindings)));
if (success) {
- debuglf(specline, lit("until/last matched ~a:~a"),
+ debuglf(specline, lit("until/last matched ~a:~d"),
c->curfile, c->data_lineno, nao);
/* Until discards bindings and position, last keeps them. */
if (sym == last_s) {
@@ -2880,7 +2880,7 @@ static val v_collect(match_files_ctx *c)
c->bindings, eq_f, nil);
val have_new = strictly_new_bindings;
- debuglf(specline, lit("collect matched ~a:~a"),
+ debuglf(specline, lit("collect matched ~a:~d"),
c->curfile, c->data_lineno, nao);
for (iter = vars; iter; iter = cdr(iter)) {
@@ -2923,7 +2923,7 @@ static val v_collect(match_files_ctx *c)
new_line = plus(new_line, one);
}
- debuglf(specline, lit("collect advancing from line ~a to ~a"),
+ debuglf(specline, lit("collect advancing from line ~d to ~d"),
c->data_lineno, new_line, nao);
c->data = new_data;
@@ -2959,7 +2959,7 @@ next_collect:
}
if ((times || mintimes) && timescounter < ctimin) {
- debuglf(specline, lit("fewer than ~a iterations collected"),
+ debuglf(specline, lit("fewer than ~d iterations collected"),
num(ctimin), nao);
return nil;
}
@@ -3294,7 +3294,7 @@ static val v_output(match_files_ctx *c)
"treating as failed match due to nothrow"), dest, nao);
return nil;
} else if (errno != 0) {
- file_err(specline, lit("could not open ~a (error ~a/~a)"), dest,
+ file_err(specline, lit("could not open ~a (error ~d/~s)"), dest,
num(errno), string_utf8(strerror(errno)), nao);
} else {
file_err(specline, lit("could not open ~a"), dest, nao);
@@ -3575,7 +3575,7 @@ static val v_filter(match_files_ctx *c)
static val v_eof(match_files_ctx *c)
{
if (c->data && car(c->data)) {
- debuglf(c->spec, lit("eof failed to match at ~a"), c->data_lineno, nao);
+ debuglf(c->spec, lit("eof failed to match at ~d"), c->data_lineno, nao);
return nil;
}
return next_spec_k;
@@ -3660,7 +3660,7 @@ static val v_fun(match_files_ctx *c)
if (consp(success)) {
debuglf(specline,
lit("function matched; "
- "advancing from line ~a to ~a"),
+ "advancing from line ~d to ~d"),
c->data_lineno, cdr(success), nao);
c->data = car(success);
c->data_lineno = cdr(success);
@@ -3723,8 +3723,8 @@ static val v_assert(match_files_ctx *c)
uw_throw(type, values);
} else {
if (c->curfile)
- typed_error(assert_s, first_spec, lit("assertion (at ~s:~s)"), c->curfile, c->data_lineno, nao);
- typed_error(assert_s, first_spec, lit("assertion (line ~s)"), c->data_lineno, nao);
+ typed_error(assert_s, first_spec, lit("assertion (at ~s:~d)"), c->curfile, c->data_lineno, nao);
+ typed_error(assert_s, first_spec, lit("assertion (line ~d)"), c->data_lineno, nao);
}
}
abort();
@@ -3785,7 +3785,7 @@ static val v_load(match_files_ctx *c)
if (consp(success)) {
debuglf(specline,
lit("load: ~s matched; "
- "advancing from line ~a to ~a"),
+ "advancing from line ~d to ~d"),
path, c->data_lineno, cdr(success), nao);
c->data = car(success);
c->data_lineno = cdr(success);
@@ -3834,7 +3834,7 @@ static val v_line(match_files_ctx *c)
c->bindings = dest_bind(specline, c->bindings, pat, c->data_lineno, eql_f);
if (c->bindings == t) {
- debuglf(specline, lit("line mismatch (line ~a vs. ~a)"), c->data_lineno, pat, nao);
+ debuglf(specline, lit("line mismatch (line ~d vs. ~d)"), c->data_lineno, pat, nao);
return nil;
}
@@ -3865,8 +3865,8 @@ static val h_assert(match_line_ctx *c)
uw_throw(type, values);
} else {
if (c->file)
- typed_error(assert_s, elem, lit("assertion (at ~s:~s)"), c->file, c->data_lineno, nao);
- typed_error(assert_s, elem, lit("assertion (line ~s)"), c->data_lineno, nao);
+ typed_error(assert_s, elem, lit("assertion (at ~s:~d)"), c->file, c->data_lineno, nao);
+ typed_error(assert_s, elem, lit("assertion (line ~d)"), c->data_lineno, nao);
}
abort();
}
@@ -3900,7 +3900,7 @@ static void open_data_source(match_files_ctx *c)
debuglf(spec, lit("could not open ~a: "
"treating as failed match due to nothrow"), name, nao);
else if (errno != 0)
- file_err(spec, lit("could not open ~a (error ~a/~a)"), name,
+ file_err(spec, lit("could not open ~a (error ~d/~s)"), name,
num(errno), string_utf8(strerror(errno)), nao);
else
file_err(spec, lit("could not open ~a"), name, nao);
diff --git a/parser.c b/parser.c
index 1924cad0..258c77b8 100644
--- a/parser.c
+++ b/parser.c
@@ -673,10 +673,10 @@ val repl(val bindings, val in_stream, val out_stream)
lino_hist_load(ls, histfile_u8);
while (!done) {
- val prompt = format(nil, lit("~a> "), counter, nao);
+ val prompt = format(nil, lit("~d> "), counter, nao);
val prev_counter = counter;
val var_counter = mod(counter, num_fast(100));
- val var_name = format(nil, lit("*~a"), var_counter, nao);
+ val var_name = format(nil, lit("*~d"), var_counter, nao);
val var_sym = intern(var_name, user_package);
char *prompt_u8 = utf8_dup_to(c_str(prompt));
@@ -726,7 +726,7 @@ val repl(val bindings, val in_stream, val out_stream)
uw_catch_begin (catch_all, exsym, exvals);
{
- val name = format(nil, lit("expr-~a"), prev_counter, nao);
+ val name = format(nil, lit("expr-~d"), prev_counter, nao);
val line = string_utf8(line_u8);
val form = lisp_parse(line, out_stream, colon_k, name, colon_k);
if (form == quit_k) {
diff --git a/parser.l b/parser.l
index 68767f7e..fe16330d 100644
--- a/parser.l
+++ b/parser.l
@@ -109,10 +109,10 @@ void yyerrorf(scanner_t *scanner, val fmt, ...)
va_list vl;
va_start (vl, fmt);
if (opt_compat && opt_compat <= 114)
- format(std_error, lit("~a: (~a:~a): "), prog_string,
+ format(std_error, lit("~a: (~a:~d): "), prog_string,
parser->name, num(parser->lineno), nao);
else
- format(std_error, lit("~a:~a: "),
+ format(std_error, lit("~a:~d: "),
parser->name, num(parser->lineno), nao);
vformat(std_error, fmt, vl);
@@ -1037,7 +1037,7 @@ val source_loc_str(val form, val alt)
cons_bind (line, file, gethash(form_to_ln_hash, form));
if (missingp(alt))
alt = lit("source location n/a");
- return if3(line, format(nil, lit("~a:~a"), file, line, nao), alt);
+ return if3(line, format(nil, lit("~a:~d"), file, line, nao), alt);
}
int yylex(YYSTYPE *yylval_param, yyscan_t yyscanner)
diff --git a/stream.c b/stream.c
index ade41325..9c0fabda 100644
--- a/stream.c
+++ b/stream.c
@@ -63,7 +63,7 @@
val stdin_s, stdout_s, stddebug_s, stderr_s, stdnull_s;
-val print_flo_precision_s;
+val print_flo_precision_s, print_base_s;
val from_start_k, from_current_k, from_end_k;
val real_time_k, name_k, fd_k;
@@ -366,7 +366,7 @@ static val stdio_maybe_read_error(val stream)
if (ferror(h->f)) {
val err = num(errno);
h->err = err;
- uw_throwf(file_error_s, lit("error reading ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("error reading ~a: ~d/~s"),
stream, err, errno_to_string(err), nao);
}
if (feof(h->f))
@@ -381,7 +381,7 @@ static val stdio_maybe_error(val stream, val action)
if (h->f == 0)
uw_throwf(file_error_s, lit("error ~a ~a: file closed"), stream, action, nao);
h->err = err;
- uw_throwf(file_error_s, lit("error ~a ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("error ~a ~a: ~d/~s"),
stream, action, err, errno_to_string(err), nao);
}
@@ -655,7 +655,7 @@ static val stdio_close(val stream, val throw_on_error)
h->f = 0;
if (result == EOF && throw_on_error) {
h->err = num(errno);
- uw_throwf(file_error_s, lit("error closing ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("error closing ~a: ~d/~s"),
stream, num(errno), string_utf8(strerror(errno)), nao);
}
return result != EOF ? t : nil;
@@ -932,7 +932,7 @@ static val pipe_close(val stream, val throw_on_error)
if (status < 0) {
if (throw_on_error)
uw_throwf(process_error_s,
- lit("unable to obtain status of command ~a: ~a/~s"),
+ lit("unable to obtain status of command ~a: ~d/~s"),
stream, num(errno), string_utf8(strerror(errno)), nao);
} else {
#ifdef HAVE_SYS_WAIT
@@ -2185,12 +2185,13 @@ val formatv(val stream_in, val fmtstr, struct args *al)
} state = vf_init, saved_state = vf_init;
int width = 0, precision = 0, precision_p = 0, digits = 0, lt = 0, neg = 0;
enum align align = al_right;
- int sign = 0, zeropad = 0, dfl_precision = 0;
+ int sign = 0, zeropad = 0, dfl_precision = 0, print_base = 0;
cnum value;
cnum arg_ix = 0;
for (;;) {
val obj;
+ type_t typ;
wchar_t ch = *fmt++;
char num_buf[512], *pnum = num_buf;
@@ -2323,7 +2324,9 @@ val formatv(val stream_in, val fmtstr, struct args *al)
switch (ch) {
case 'x': case 'X':
obj = args_get_checked(name, al, &arg_ix);
- if (bignump(obj)) {
+ typ = type(obj);
+ hex:
+ if (typ == BGNUM) {
int nchars = mp_radix_size(mp(obj), 16);
if (nchars >= convert(int, sizeof (num_buf)))
pnum = coerce(char *, chk_malloc(nchars + 1));
@@ -2341,7 +2344,9 @@ val formatv(val stream_in, val fmtstr, struct args *al)
goto output_num;
case 'o': case 'b':
obj = args_get_checked(name, al, &arg_ix);
- if (bignump(obj)) {
+ typ = type(obj);
+ oct:
+ if (typ == BGNUM) {
int rad = ch == '0' ? 8 : 2;
int nchars = mp_radix_size(mp(obj), rad);
if (nchars >= convert(int, sizeof (num_buf)))
@@ -2438,10 +2443,36 @@ val formatv(val stream_in, val fmtstr, struct args *al)
precision = 0;
goto output_num;
}
+ case 'd':
+ obj = args_get_checked(name, al, &arg_ix);
+ typ = type(obj);
+ goto dec;
case 'a': case 's':
obj = args_get_checked(name, al, &arg_ix);
-
- switch (type(obj)) {
+ typ = type(obj);
+
+ if (typ == NUM || typ == BGNUM) {
+ if (!print_base)
+ print_base = c_num(cdr(lookup_var(nil, print_base_s)));
+ switch (print_base) {
+ case 0:
+ case 2:
+ ch = 'b';
+ goto oct;
+ case 8:
+ ch = 'o';
+ goto oct;
+ case 16:
+ ch = 'X';
+ goto hex;
+ case 10:
+ default:
+ break;
+ }
+ }
+ /* fallthrough */
+ dec:
+ switch (typ) {
case NUM:
value = c_num(obj);
sprintf(num_buf, num_fmt->dec, value);
@@ -2854,7 +2885,7 @@ val open_directory(val path)
DIR *d = w_opendir(c_str(path));
if (!d)
- uw_throwf(file_error_s, lit("error opening directory ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("error opening directory ~a: ~d/~s"),
path, num(errno), string_utf8(strerror(errno)), nao);
return make_dir_stream(d);
@@ -2866,7 +2897,7 @@ val open_file(val path, val mode_str)
FILE *f = w_fopen(c_str(path), c_str(normalize_mode(&m, mode_str)));
if (!f)
- uw_throwf(file_error_s, lit("error opening ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("error opening ~a: ~d/~s"),
path, num(errno), string_utf8(strerror(errno)), nao);
return set_mode_props(m, make_stdio_stream(f, path));
@@ -2878,11 +2909,11 @@ val open_fileno(val fd, val mode_str)
FILE *f = w_fdopen(c_num(fd), c_str(normalize_mode(&m, mode_str)));
if (!f)
- uw_throwf(file_error_s, lit("error opening descriptor ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("error opening descriptor ~a: ~d/~s"),
fd, num(errno), string_utf8(strerror(errno)), nao);
return set_mode_props(m, make_stdio_stream(f, format(nil,
- lit("fd ~a"),
+ lit("fd ~d"),
fd, nao)));
}
@@ -2897,7 +2928,7 @@ val open_tail(val path, val mode_str, val seek_end_p)
if (f && default_bool_arg(seek_end_p))
if (fseek(f, 0, SEEK_END) < 0)
- uw_throwf(file_error_s, lit("error seeking to end of ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("error seeking to end of ~a: ~d/~s"),
path, num(errno), string_utf8(strerror(errno)), nao);
stream = make_tail_stream(f, path);
@@ -2914,7 +2945,7 @@ val open_command(val path, val mode_str)
FILE *f = w_popen(c_str(path), c_str(normalize_mode(&m, mode_str)));
if (!f)
- uw_throwf(file_error_s, lit("error opening pipe ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("error opening pipe ~a: ~d/~s"),
path, num(errno), string_utf8(strerror(errno)), nao);
return set_mode_props(m, make_pipe_stream(f, path));
@@ -2936,7 +2967,7 @@ val open_process(val name, val mode_str, val args)
nargs = c_num(length(args)) + 1;
if (pipe(fd) == -1) {
- uw_throwf(file_error_s, lit("opening pipe ~a, pipe syscall failed: ~a/~s"),
+ uw_throwf(file_error_s, lit("opening pipe ~a, pipe syscall failed: ~d/~s"),
name, num(errno), string_utf8(strerror(errno)), nao);
}
@@ -2954,7 +2985,7 @@ val open_process(val name, val mode_str, val args)
for (i = 0; i < nargs; i++)
free(argv[i]);
free(argv);
- uw_throwf(file_error_s, lit("opening pipe ~a, fork syscall failed: ~a/~s"),
+ uw_throwf(file_error_s, lit("opening pipe ~a, fork syscall failed: ~d/~s"),
name, num(errno), string_utf8(strerror(errno)), nao);
}
@@ -3001,7 +3032,7 @@ val open_process(val name, val mode_str, val args)
while (waitpid(pid, &status, 0) == -1 && errno == EINTR)
;
free(utf8mode);
- uw_throwf(file_error_s, lit("opening pipe ~a, fdopen failed: ~a/~s"),
+ uw_throwf(file_error_s, lit("opening pipe ~a, fdopen failed: ~d/~s"),
name, num(errno), string_utf8(strerror(errno)), nao);
}
@@ -3130,7 +3161,7 @@ static val run(val name, val args)
for (i = 0; i < nargs; i++)
free(argv[i]);
free(argv);
- uw_throwf(file_error_s, lit("opening process ~a, fork syscall failed: ~a/~s"),
+ uw_throwf(file_error_s, lit("opening process ~a, fork syscall failed: ~d/~s"),
name, num(errno), string_utf8(strerror(errno)), nao);
}
@@ -3196,7 +3227,7 @@ static val sh(val command)
val remove_path(val path)
{
if (w_remove(c_str(path)) < 0)
- uw_throwf(file_error_s, lit("trying to remove ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("trying to remove ~a: ~d/~s"),
path, num(errno), string_utf8(strerror(errno)), nao);
return t;
}
@@ -3204,7 +3235,7 @@ val remove_path(val path)
val rename_path(val from, val to)
{
if (w_rename(c_str(from), c_str(to)) < 0)
- uw_throwf(file_error_s, lit("trying to rename ~a to ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("trying to rename ~a to ~a: ~d/~s"),
from, to, num(errno), string_utf8(strerror(errno)), nao);
return t;
}
@@ -3279,6 +3310,8 @@ void stream_init(void)
reg_var(print_flo_precision_s = intern(lit("*print-flo-precision*"),
user_package),
num_fast(DBL_DIG));
+ reg_var(print_base_s = intern(lit("*print-base*"), user_package),
+ num_fast(10));
#if HAVE_ISATTY
if (isatty(fileno(stdin)) == 1)
diff --git a/sysif.c b/sysif.c
index b4f2df52..7c6f697d 100644
--- a/sysif.c
+++ b/sysif.c
@@ -191,7 +191,7 @@ static val mkdir_wrap(val path, val mode)
free(u8path);
if (err < 0)
- uw_throwf(file_error_s, lit("mkdir ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("mkdir ~a: ~d/~s"),
path, num(errno), string_utf8(strerror(errno)), nao);
return t;
@@ -203,7 +203,7 @@ static val mkdir_wrap(val path, val mode)
(void) mode;
if (err < 0)
- uw_throwf(file_error_s, lit("mkdir ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("mkdir ~a: ~d/~s"),
path, num(errno), string_utf8(strerror(errno)), nao);
return t;
@@ -265,7 +265,7 @@ static val ensure_dir(val path, val mode)
if (ret != t)
uw_throwf(file_error_s,
- lit("ensure-dir: ~a: ~a/~s"), path, ret,
+ lit("ensure-dir: ~a: ~d/~s"), path, ret,
string_utf8(strerror(c_num(ret))), nao);
return ret;
@@ -280,7 +280,7 @@ static val chdir_wrap(val path)
free(u8path);
if (err < 0)
- uw_throwf(file_error_s, lit("chdir ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("chdir ~a: ~d/~s"),
path, num(errno), string_utf8(strerror(errno)), nao);
return t;
}
@@ -295,7 +295,7 @@ static val getcwd_wrap(void)
if (getcwd(u8buf, guess) == 0) {
free(u8buf);
if (errno != ERANGE) {
- uw_throwf(file_error_s, lit("getcwd: ~a/~s"),
+ uw_throwf(file_error_s, lit("getcwd: ~d/~s"),
num(errno), string_utf8(strerror(errno)), nao);
}
if (2 * guess > guess)
@@ -340,11 +340,11 @@ static val mknod_wrap(val path, val mode, val dev)
if (err < 0)
#if HAVE_MAKEDEV
- uw_throwf(file_error_s, lit("mknod ~a ~a ~a (~a:~a): ~a/~s"),
+ uw_throwf(file_error_s, lit("mknod ~a ~a ~a (~d:~d): ~d/~s"),
path, mode, dev, major_wrap(dev), minor_wrap(dev), num(errno),
string_utf8(strerror(errno)), nao);
#else
- uw_throwf(file_error_s, lit("mknod ~a ~a ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("mknod ~a ~a ~a: ~d/~s"),
path, mode, dev, num(errno),
string_utf8(strerror(errno)), nao);
#endif
@@ -363,7 +363,7 @@ static val chmod_wrap(val path, val mode)
free(u8path);
if (err < 0)
- uw_throwf(file_error_s, lit("chmod ~a ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("chmod ~a #o~o: ~d/~s"),
path, mode, num(errno), string_utf8(strerror(errno)), nao);
return t;
}
@@ -380,7 +380,7 @@ static val symlink_wrap(val target, val to)
free(u8target);
free(u8to);
if (err < 0)
- uw_throwf(file_error_s, lit("symlink ~a ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("symlink ~a ~a: ~d/~s"),
target, to, num(errno), string_utf8(strerror(errno)), nao);
return t;
}
@@ -393,7 +393,7 @@ static val link_wrap(val target, val to)
free(u8target);
free(u8to);
if (err < 0)
- uw_throwf(file_error_s, lit("link ~a ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("link ~a ~a: ~d/~s"),
target, to, num(errno), string_utf8(strerror(errno)), nao);
return t;
}
@@ -415,7 +415,7 @@ static val readlink_wrap(val path)
uw_throwf(file_error_s, lit("readlink: weird problem"), nao);
} else if (bytes <= 0) {
free(u8buf);
- uw_throwf(file_error_s, lit("readlink ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("readlink ~a: ~d/~s"),
path, num(errno), string_utf8(strerror(errno)), nao);
} else {
val out;
@@ -521,7 +521,7 @@ static val exec_wrap(val file, val args_opt)
argv[i] = 0;
if (execvp(argv[0], argv) < 0)
- uw_throwf(file_error_s, lit("execvp ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("execvp ~a: ~d/~s"),
file, num(errno), string_utf8(strerror(errno)), nao);
uw_throwf(file_error_s, lit("execvp ~a returned"), file, nao);
}
@@ -639,7 +639,7 @@ static val stat_impl(val obj, int (*statfn)(val, struct stat *),
int res = statfn(obj, &st);
if (res == -1)
- uw_throwf(file_error_s, lit("unable to ~a ~a: ~a/~s"),
+ uw_throwf(file_error_s, lit("unable to ~a ~a: ~d/~s"),
name, obj, num(errno), string_utf8(strerror(errno)), nao);
return if3(opt_compat && opt_compat <= 113,
@@ -670,7 +670,7 @@ static val pipe_wrap(void)
{
int fd[2];
if (pipe(fd) < 0)
- uw_throwf(file_error_s, lit("pipe failed: ~a/~s"),
+ uw_throwf(file_error_s, lit("pipe failed: ~d/~s"),
num(errno), string_utf8(strerror(errno)), nao);
return cons(num(fd[0]), num(fd[1]));
}
@@ -749,7 +749,7 @@ static val poll_wrap(val poll_list, val timeout_in)
if (res < 0) {
free(pfd);
- uw_throwf(file_error_s, lit("poll failed: ~a/~s"),
+ uw_throwf(file_error_s, lit("poll failed: ~d/~s"),
num(errno), string_utf8(strerror(errno)), nao);
}
@@ -820,7 +820,7 @@ static val getgroups_wrap(void)
free(arr);
}
- uw_throwf(system_error_s, lit("getgroups failed: ~a/~s"),
+ uw_throwf(system_error_s, lit("getgroups failed: ~d/~s"),
num(errno), string_utf8(strerror(errno)), nao);
abort();
}
@@ -828,7 +828,7 @@ static val getgroups_wrap(void)
static val setuid_wrap(val nval)
{
if (setuid(c_num(nval)) == -1)
- uw_throwf(system_error_s, lit("setuid failed: ~a/~s"),
+ uw_throwf(system_error_s, lit("setuid failed: ~d/~s"),
num(errno), string_utf8(strerror(errno)), nao);
return t;
}
@@ -836,7 +836,7 @@ static val setuid_wrap(val nval)
static val seteuid_wrap(val nval)
{
if (seteuid(c_num(nval)) == -1)
- uw_throwf(system_error_s, lit("seteuid failed: ~a/~s"),
+ uw_throwf(system_error_s, lit("seteuid failed: ~d/~s"),
num(errno), string_utf8(strerror(errno)), nao);
return t;
}
@@ -844,7 +844,7 @@ static val seteuid_wrap(val nval)
static val setgid_wrap(val nval)
{
if (setgid(c_num(nval)) == -1)
- uw_throwf(system_error_s, lit("setgid failed: ~a/~s"),
+ uw_throwf(system_error_s, lit("setgid failed: ~d/~s"),
num(errno), string_utf8(strerror(errno)), nao);
return t;
}
@@ -852,7 +852,7 @@ static val setgid_wrap(val nval)
static val setegid_wrap(val nval)
{
if (setegid(c_num(nval)) == -1)
- uw_throwf(system_error_s, lit("setegid failed: ~a/~s"),
+ uw_throwf(system_error_s, lit("setegid failed: ~d/~s"),
num(errno), string_utf8(strerror(errno)), nao);
return t;
}
diff --git a/txr.1 b/txr.1
index 79fa9520..13940ef2 100644
--- a/txr.1
+++ b/txr.1
@@ -30798,6 +30798,41 @@ to the value of the
.code flo-max-dig
variable.
+.coNP Special variable @ *print-base*
+.desc
+The
+.code *print-base*
+variable controls the base (radix) used for printing integer values.
+It applies when the functions
+.codn print ,
+.cond pprint ,
+.cond prinl ,
+.cond pprinl ,
+.code tostring
+and
+.codn tostringp
+process an integer value.
+It also applies when the
+.code ~a
+and
+.code ~s
+conversion specifiers of the
+.code format
+function are used for printing an integer value.
+
+The default value of the variable is
+.codn 10 .
+
+Meaningful values are:
+.codn 2 ,
+.codn 8 ,
+.code 10
+and
+.codn 16 .
+
+When base 16 is selected, hexadecimal digits are printed as upper-case
+characters.
+
.coNP Function @ format
.synb
.mets (format < stream-designator < format-string << format-arg *)
@@ -31044,7 +31079,20 @@ for the sake of read-print
consistency. Objects truncated by precision may not have read-print
consistency. For instance, if a string object is truncated, it loses its
trailing closing quote, so that the resulting representation is no longer
-a properly formed string object.
+a properly formed string object. For integer objects, the
+.code *print-base*
+variable is honored. Effectively, an integer is printed by the
+.code s
+directive as if by the
+.codn b ,
+.codn o ,
+.codn d ,
+or
+.code x directive, depending on the value of the variable.
+
+.coIP d
+Requires an argument of integer or character type type. The integer
+value or character code is printed in decimal.
.coIP x
Requires an argument of character or integer type. The integer value or