summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2024-11-14 18:23:49 -0800
committerKaz Kylheku <kaz@kylheku.com>2024-11-14 18:23:49 -0800
commit0bbcfdeac48bd39192c8fe3f54ed77c07782e493 (patch)
tree5f8d361b93c34695caa54ea2b8bf2a4410bd5536
parent985da46414c246d1dc94e5b6f40899c9159e2d0e (diff)
downloadtxr-0bbcfdeac48bd39192c8fe3f54ed77c07782e493.tar.gz
txr-0bbcfdeac48bd39192c8fe3f54ed77c07782e493.tar.bz2
txr-0bbcfdeac48bd39192c8fe3f54ed77c07782e493.zip
switch to .txr-profile and .txr-history
The profile and history files should have used hyphens from the beginning. Let's switch to that but continue to work with the old files if present, as an obsolescent feature. * parser.c (open_txr_file): Treat files with .txr-profile suffix as Lisp. (load_rcfile): Arguments rearranged. This function now needs the home directory and the existence test function, but does not need the profile file name. It tries .txr-profile first, then .txr-profile. (repl): Call load_rcfile in the new way. Try two history files: first .txr-history and then .txr_history. Remember which one was used so the same one is saved. If neither file existed at startup, then save new history into .txr-history. * txr.1: Documented.
-rw-r--r--parser.c39
-rw-r--r--txr.152
-rw-r--r--txr.c2
3 files changed, 74 insertions, 19 deletions
diff --git a/parser.c b/parser.c
index 8b17cba7..e60166cc 100644
--- a/parser.c
+++ b/parser.c
@@ -538,6 +538,8 @@ void open_txr_file(val first_try_path, val *txr_lisp_p,
suffix = tlo;
else if (match_str(first_try_path, lit(".tlo.gz"), negone))
suffix = tlz;
+ else if (match_str(first_try_path, lit(".txr-profile"), negone))
+ suffix = tl;
else if (match_str(first_try_path, lit(".txr_profile"), negone))
suffix = tl;
else
@@ -1026,12 +1028,17 @@ static void report_path_perm_problem(val name)
#endif
}
-static void load_rcfile(val name, val psafe_s, val ppriv_s)
+static void load_rcfile(val home, val pexist_s, val psafe_s, val ppriv_s)
{
val self = lit("listener");
- val resolved_name = name;
val lisp_p = t;
val stream = nil;
+ val try1 = scat2(home, lit("/.txr-profile"));
+ val try2 = scat2(home, lit("/.txr_profile"));
+
+ val name = if3(funcall1(pexist_s, try1), try1,
+ if2(funcall1(pexist_s, try2), try2));
+ val resolved_name = name;
if (!funcall1(psafe_s, name)) {
report_path_perm_problem(name);
@@ -1645,9 +1652,12 @@ val repl(val bindings, val in_stream, val out_stream, val env)
val done = nil;
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, self), NULL);
- val rcfile = if2(home && !opt_noprofile, scat2(home, lit("/.txr_profile")));
+ val hist1 = if2(home, scat2(home, lit("/.txr-history")));
+ val hist2 = if2(home, scat2(home, lit("/.txr_history")));
+ val histfile;
+ const wchar_t *hist1_w = if3(home, c_str(hist1, self), 0);
+ const wchar_t *hist2_w = if3(home, c_str(hist2, self), 0);
+ const wchar_t *histfile_w = 0;
val old_sig_handler = set_sig_handler(num(SIGINT), func_n2(repl_intr));
val hist_len_var = lookup_global_var(listener_hist_len_s);
#if CONFIG_FULL_REPL
@@ -1690,12 +1700,20 @@ val repl(val bindings, val in_stream, val out_stream, val env)
lino_set_enter_cb(ls, is_balanced_line, 0);
lino_set_tempfile_suffix(ls, ".tl");
- if (rcfile && funcall1(pexist_s, rcfile))
- load_rcfile(rcfile, psafe_s, ppriv_s);
+ if (home && !opt_noprofile)
+ load_rcfile(home, pexist_s, psafe_s, ppriv_s);
lino_hist_set_max_len(ls, c_num(cdr(hist_len_var), self));
- if (histfile_w && funcall1(pexist_s, histfile)) {
+ if (hist1_w && funcall1(pexist_s, hist1)) {
+ histfile = hist1;
+ histfile_w = hist1_w;
+ } else if (hist2_w && funcall1(pexist_s, hist2)) {
+ histfile = hist2;
+ histfile_w = hist2_w;
+ }
+
+ if (histfile_w) {
if (!funcall1(psafe_s, home)) {
report_path_perm_problem(home);
} else if (!funcall1(ppriv_s, histfile)) {
@@ -1705,6 +1723,11 @@ val repl(val bindings, val in_stream, val out_stream, val env)
lino_hist_load(ls, histfile_w);
}
+ if (home && !histfile_w) {
+ histfile = hist1;
+ histfile_w = hist1_w;
+ }
+
#if CONFIG_FULL_REPL
lino_set_noninteractive(ls, opt_noninteractive);
#endif
diff --git a/txr.1 b/txr.1
index 5f888d4f..8596823e 100644
--- a/txr.1
+++ b/txr.1
@@ -1011,7 +1011,8 @@ If the file has a recognized suffix:
.strn .tl ,
.strn .tlo ,
.strn .tlo.gz ,
-.str .txr
+.strn .txr ,
+.str .txr-profile
or
.strn .txr_profile ,
then these options have no effect. The suffix determines the
@@ -1040,7 +1041,7 @@ See the section SETUID/SETGID OPERATION.
.coIP --noprofile
If entering the interactive listener, suppress the reading of the
-.code .txr_profile
+.code .txr-profile
in the home directory. See the Interactive Profile File subsection in the
INTERACTIVE LISTENER section of the manual.
@@ -83230,7 +83231,8 @@ ends in any of these four suffixes:
.codn .tlo ,
.codn .tlo.gz ,
.codn .tl ,
-.code .txr
+.codn .txr ,
+.code .txr-profile
or
.codn .txr_profile .
@@ -83288,6 +83290,8 @@ a file results in an error other than non-existence.
If an unsuffixed file is successfully opened, its contents are treated as
interpreted Lisp. Files ending in
+.code .txr-profile
+or
.code .txr_profile
are also treated as interpreted Lisp. Files ending in
.code .tlo
@@ -83616,7 +83620,7 @@ are executed first. However, their executions do not interleave.
Note that
.code *load-hooks*
is not processed after the listener reads the
-.code .txr_profile
+.code .txr-profile
file. Hooks installed by the profile file will activate when the process
exits.
@@ -94318,7 +94322,7 @@ expression.
Unless the
.code --noprofile
option has been used, when the listener starts up, it looks for file called
-.code .txr_profile
+.code .txr-profile
in the user's home directory, as determined by the
.code HOME
environment variable in POSIX environments or the
@@ -94326,7 +94330,19 @@ environment variable in POSIX environments or the
environment variable on MS Windows. If that variable doesn't exist, no further
attempt is made to locate this file.
-If the file exists, it is subject to security checks. First, the
+If the
+.code .txr-profile
+file does not exist, but
+.code .txr_profile
+exists, then that file is taken as the profile file instead.
+Falling back on
+.code .txr_profile
+is obsolescent and will be removed in some future version of \*(TX.
+The switch to
+.code .txr-profile
+was introduced in \*(TX 297.
+
+If the history file exists, it is subject to security checks. First, the
.code path-components-safe
is applied to its path name. The function validates that no component
of the path name is a directory that is writable to another user, or
@@ -94356,7 +94372,7 @@ option isn't present.
.SS* History Persistence
The history is maintained in a text file called
-.code .txr_history
+.code .txr-history
in the user's home directory. Whenever the interactive listener terminates,
this file is updated with the history contents stored in the listener's
memory. The next time the listener starts, it first reloads the history from
@@ -94364,6 +94380,19 @@ this file, making the most recent
.code *listener-hist-len*
expressions of a previous session available for recall.
+If the
+.code .txr-history
+file does not exist, but a file called
+.code .txr_history
+exists, then that file is loaded instead and that same file will be
+written to when the history is saved. This behavior is obsolescent;
+support for recognizing a
+.code .txr_history
+file will be removed in a future release of \*(TX.
+The switch to
+.code .txr-history
+was introduced in \*(TX 297.
+
The history file is maintained in a way that is somewhat
robust against the loss of history arising from the situation that a user
manages multiple simultaneous \*(TX sessions. When a session terminates, it
@@ -94406,7 +94435,7 @@ command.
When the history file is loaded, security checks take place, in exactly
the same way that the
-.str .txr_profile
+.str .txr-profile
file is validated. First the path of the history file is checked using
the function
.codn path-components-safe ,
@@ -94704,7 +94733,7 @@ The
.code quip
function returns a randomly selected string containing a humorous quip,
quote or witticism. The following code may be added to
-.code .txr_profile
+.code .txr-profile
to produce a random quip on startup:
.verb
@@ -94714,7 +94743,7 @@ to produce a random quip on startup:
The
.code quip
function was introduced in \*(TX 244. If the
-.code .txr_profile
+.code .txr-profile
is used with installations of older \*(TX versions, it is recommended to use
the following, to avoid calling the undefined function, as well as to
prevent a warning:
@@ -94725,6 +94754,9 @@ prevent a warning:
(defun quip ()))
.brev
+In addition, older \*(TX versions require the profile file to be named
+.codn .txr_profile .
+
.SH* SETUID/SETGID OPERATION
On platforms with the Unix filesystem and process security model, \*(TX has
diff --git a/txr.c b/txr.c
index d1c02db0..2978b904 100644
--- a/txr.c
+++ b/txr.c
@@ -179,7 +179,7 @@ static void help(void)
" the following argument arg and allows one or more\n"
" copies of it to be to be embedded in the\n"
" encoded arguments. See the manual.\n"
-"--noprofile Do not read .txr_profile when entering listener.\n"
+"--noprofile Do not read .txr-profile when entering listener.\n"
IF_HAVE_FORK_STUFF(
"--reexec Re-execute TXR with remaining arguments.\n",
""