summaryrefslogtreecommitdiffstats
path: root/parser.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-23 06:24:54 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-23 06:24:54 -0700
commitad4e4e79ac6b9fcb182f3cd834120ec79512ac9a (patch)
tree44aae8e017bc51f526fded0d85bf3a63ba00ad8f /parser.c
parenteed035b792cb3b1b2723fa2b1ca0dd7fb5e5fe31 (diff)
downloadtxr-ad4e4e79ac6b9fcb182f3cd834120ec79512ac9a.tar.gz
txr-ad4e4e79ac6b9fcb182f3cd834120ec79512ac9a.tar.bz2
txr-ad4e4e79ac6b9fcb182f3cd834120ec79512ac9a.zip
c_str now takes a self argument.
Adding a self parameter to c_str so that when a non-string occurs, the error is reported against a function. Legend: A - Pass existing self to c_str. B - Define self and pass to c_str and possibly other functions. C - Take new self parameter and pass to c_str and possibly other functions. D - Pass existing self to c_str and/or other functions. E - Define self and pass to other functions, not c_str. X - Pass nil to c_str. * buf.c (buf_strm_put_string, buf_str): B. * chksum.c (sha256_str, md5_str): C. (sha256_hash, md5_hash): D. * eval.c (load): D. * ffi.c (ffi_varray_dynsize, ffi_str_put, ffi_wstr_put, ffi_bstr_put): A. (ffi_char_array_put, ffi_wchar_array_put): C. (ffi_bchar_array_put): A. (ffi_array_put, ffi_array_out, ffi_varray_put): D. * ftw.c (ftw_wrap): A. * glob.c (glob_wrap): A. * lib.c (copy_str, length_str, coded_length,split_str_set, list_str, cmp_str, num_str, out_json_str, out_json_rec, display_width): B. (upcase_str, downcase_str, string_extend, search_str, do_match_str, do_rmatch_str, sub_str, replace_str, cat_str_append, split_str_keep, trim_str, int_str, chr_str, span_str, compl_span_str, break_str, length_str_gt, length_str_ge, length_str_lt, length_str_le, find, rfind, pos, rpos, mismatch, rmismatch): A. (c_str): Add self parameter and use in type mismatch diagnostic. If the parameter is nil, use "internal error". (flo_str): B, and correction to "flot-str" typo. (out_lazy_str, out_quasi_str, obj_print_impl): D. * lib.h (c_str): Declaration updated. * match.c (dump_var): X. (v_load): D. * parser.c (open_txr_file): C. (load_rcfile): E. (find_matching_syms, provide_atom): X. (hist_save, repl): B. * parser.h (open_txr_file): Declaration updated. * parser.y (chrlit): X. * regex.c (search_regex): A. * socket.c (getaddrinfo_wrap, sockaddr_pack): A. (dgram_put_string): B. (open_sockfd): D. (sock_connect): E. * stream.c (stdio_put_string, tail_strategy, vformat_str, open_directory, open_file, open_tail, remove_path, rename_path, tmpfile_wrap, mkdtemp_wrap, mkstemp_wrap): B. (do_parse_mode, parse_mode, make_string_byte_input_stream): B. (normalize_mode, normalize_mode_no_bin): E. (string_out_put_string, formatv, put_string, open_fileno, open_subprocess, open_command, base_name, dir_name, short_suffix, long_suffix): A. (run): D. (win_escape_cmd, win_escape_arg): X. * stream.h (parse_mode, normalize_mode, normalize_mode_no_bin): Declarations updated. * sysif.c (mkdir_wrap, do_utimes, dlopen_wrap, dlsym_wrap, dlvsym_wrap): A. (do_stat, do_lstat): C. (mkdir_nothrow_exists, ensure_dir): E. (chdir_wrap, rmdir_wrap, mkfifo_wrap, chmod_wrap, symlink_wrap, link_wrap, readlink_wrap, exec_wrap, getenv_wrap, setenv_wrap, unsetenv_wrap, getpwnam_wrap, getgrnam_wrap, crypt_wrap, fnmatch_wrap, realpath_wrap, opendir_wrap): B. (stat_impl): statfn pointer-to-function argument now takes self parameter. When calling it, we pass name. * syslog.c (openlog_wrap, syslog_wrapv): A. * time.c (time_string_local, time_string_utc, time_string_meth, time_parse_meth): A. (strptime_wrap): B. * txr.c (txr_main): D. * y.tab.c.shipped: Updated.
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/parser.c b/parser.c
index fd274ebb..2ef62537 100644
--- a/parser.c
+++ b/parser.c
@@ -508,7 +508,8 @@ val parser_circ_ref(parser_t *p, val num)
return obj;
}
-void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
+void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream,
+ val self)
{
enum { none, tl, tlo, txr } suffix;
@@ -531,7 +532,7 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
if (suffix == none && !*txr_lisp_p) {
spec_file_try = scat(lit("."), spec_file, lit("txr"), nao);
- if ((in = w_fopen(c_str(spec_file_try), L"r")) != 0)
+ if ((in = w_fopen(c_str(spec_file_try, nil), L"r")) != 0)
goto found;
#ifdef ENOENT
if (in == 0 && errno != ENOENT)
@@ -543,7 +544,7 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
{
spec_file_try = scat(lit("."), spec_file, lit("tlo"), nao);
errno = 0;
- if ((in = w_fopen(c_str(spec_file_try), L"r")) != 0) {
+ if ((in = w_fopen(c_str(spec_file_try, nil), L"r")) != 0) {
*txr_lisp_p = chr('o');
goto found;
}
@@ -555,7 +556,7 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
{
spec_file_try = scat(lit("."), spec_file, lit("tl"), nao);
errno = 0;
- if ((in = w_fopen(c_str(spec_file_try), L"r")) != 0) {
+ if ((in = w_fopen(c_str(spec_file_try, nil), L"r")) != 0) {
*txr_lisp_p = t;
goto found;
}
@@ -569,7 +570,7 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
{
spec_file_try = spec_file;
errno = 0;
- in = w_fopen(c_str(spec_file_try), L"r");
+ in = w_fopen(c_str(spec_file_try, self), L"r");
if (in != 0) {
switch (suffix) {
case tl:
@@ -886,6 +887,7 @@ static void report_security_problem(val name)
static void load_rcfile(val name)
{
+ val self = lit("listener");
val resolved_name;
val lisp_p = t;
val stream = nil;
@@ -894,7 +896,7 @@ static void load_rcfile(val name)
uw_catch_begin (catch_syms, sy, va);
- open_txr_file(name, &lisp_p, &resolved_name, &stream);
+ open_txr_file(name, &lisp_p, &resolved_name, &stream, self);
if (stream) {
if (!funcall1(path_private_to_me_p, stream)) {
@@ -902,7 +904,7 @@ static void load_rcfile(val name)
} else {
val saved_dyn_env = set_dyn_env(make_env(nil, nil, dyn_env));
env_vbind(dyn_env, load_path_s, resolved_name);
- read_eval_stream(lit("listener"), stream, std_output);
+ read_eval_stream(self, stream, std_output);
dyn_env = saved_dyn_env;
}
}
@@ -1008,7 +1010,7 @@ static void find_matching_syms(lino_completions_t *cpl,
else
comple = scat2(line_prefix, name);
- lino_add_completion(cpl, c_str(comple));
+ lino_add_completion(cpl, c_str(comple, nil));
gc_hint(comple);
}
}
@@ -1142,7 +1144,7 @@ static wchar_t *provide_atom(lino_t *l, const wchar_t *str, int n, void *ctx)
}
if (obj != nao)
- out = chk_strdup(c_str(tostring(obj)));
+ out = chk_strdup(c_str(tostring(obj), nil));
uw_catch (exsym, exvals) {
(void) exsym;
@@ -1446,7 +1448,7 @@ static void hist_save(lino_t *ls, val in_stream, val out_stream,
val self = lit("listener");
if (histfile_w && lino_have_new_lines(ls)) {
val histfile_tmp = scat2(histfile, lit(".tmp"));
- const wchar_t *histfile_tmp_w = c_str(histfile_tmp);
+ const wchar_t *histfile_tmp_w = c_str(histfile_tmp, self);
lino_t *ltmp = lino_make(coerce(mem_t *, in_stream),
coerce(mem_t *, out_stream));
lino_hist_set_max_len(ltmp, c_num(cdr(hist_len_var), self));
@@ -1483,7 +1485,7 @@ val repl(val bindings, val in_stream, val out_stream, val env)
val counter = one;
val home = if3(repl_level == 1, get_home_path(), nil);
val histfile = if2(home, scat2(home, lit("/.txr_history")));
- const wchar_t *histfile_w = if3(home, c_str(histfile), NULL);
+ const wchar_t *histfile_w = if3(home, c_str(histfile, self), NULL);
val rcfile = if2(home && !opt_noprofile, scat2(home, lit("/.txr_profile")));
val old_sig_handler = set_sig_handler(num(SIGINT), func_n2(repl_intr));
val hist_len_var = lookup_global_var(listener_hist_len_s);
@@ -1549,7 +1551,7 @@ val repl(val bindings, val in_stream, val out_stream, val env)
lino_set_selinclusive(ls, cdr(sel_inclusive_var) != nil);
reg_varl(counter_sym, counter);
reg_varl(var_counter_sym, var_counter);
- line_w = linenoise(ls, c_str(prompt));
+ line_w = linenoise(ls, c_str(prompt, self));
rplacd(multi_line_var, tnil(lino_get_multiline(ls)));
@@ -1614,7 +1616,7 @@ val repl(val bindings, val in_stream, val out_stream, val env)
reg_varl(var_sym, value);
sethash(result_hash, var_counter, value);
pfun(value, out_stream);
- lino_set_result(ls, chk_strdup(c_str(tsfun(value))));
+ lino_set_result(ls, chk_strdup(c_str(tsfun(value), self)));
lino_hist_add(ls, line_w);
if (cdr(greedy_eval)) {
val error_p = nil;