Compare commits

..

6 Commits

Author SHA1 Message Date
Landon Curt Noll
bb3b861090 Release v2.15.0.5
The following are the changes in this release:

     make clobber now removes the legacy files: have_fpos.h, help/man,
     and help/usage.  The latter 2 are now managed as help aliases
     in help.c.

     make install now removes the legacy files: ${HELPDIR}/man
     and ${HELPDIR}/usage.

     Fixed a problem where, when calc was linked with and uses GNU
     readline then for any multi-line copy-and-paste, only the first
     line is executed.  Thanks to GitHub user @malfisya for reporting
     this problem, and thanks to GitHub user @gromit1811 for doing
     the research needed to overcome deficiencies in the GNU readline
     documentation, and for supplying the work-a-round to allow
     multi-line copy-and-paste to work as expected!
2024-02-01 20:45:42 -08:00
Landon Curt Noll
0a3469125e prep CHANGES for the next release of calc 2024-02-01 20:38:19 -08:00
Landon Curt Noll
9b37e79f21 update CHANGES, fix make clobber and make install
make clobber also removes the legacy files: help/man, and help/usage.

make install now removes the legacy files: ${HELPDIR}/man and
${HELPDIR}/usage.

Document the GNU readline then for any multi-line copy-and-paste
fix in CHANGES.
2024-01-05 10:21:26 -08:00
Landon Curt Noll
18cd1f9067 Merge pull request #139 from gromit1811/master
Properly handle multi-line strings and newline returned by readline()
2024-01-05 09:51:47 -08:00
Martin Buck
43fc022dc8 Properly handle multi-line strings and newline returned by readline()
Fix for #138

According to
https://lists.gnu.org/archive/html/bug-readline/2024-01/msg00000.html
it's OK for readline() to return multi-line strings and/or newlines in case
of bracketed paste (enabled by default since readline 8.1) and also in other
situations even though its documentation explicitly states the opposite. So
we need to handle this properly in calc instead of just using the first line
and dropping the rest: Split the string returned by readline() into lines
and return line by line with each invocation of hist_getline(), each
possbily adding a terminating newline.
2024-01-05 10:34:25 +01:00
Landon Curt Noll
29695028cd improve make clobber
make clobber now removes the legacy file: have_fpos.h
2023-12-26 12:41:29 -08:00
6 changed files with 85 additions and 25 deletions

18
CHANGES
View File

@@ -1,3 +1,21 @@
The following are the changes from calc version 2.15.0.4 to 2.15.0.5:
make clobber now removes the legacy files: have_fpos.h, help/man,
and help/usage. The latter 2 are now managed as help aliases
in help.c.
make install now removes the legacy files: ${HELPDIR}/man
and ${HELPDIR}/usage.
Fixed a problem where, when calc was linked with and uses GNU
readline then for any multi-line copy-and-paste, only the first
line is executed. Thanks to GitHub user @malfisya for reporting
this problem, and thanks to GitHub user @gromit1811 for doing
the research needed to overcome deficiencies in the GNU readline
documentation, and for supplying the work-a-round to allow
multi-line copy-and-paste to work as expected!
The following are the changes from calc version 2.15.0.3 to 2.15.0.4:
Fixed bug that caused calc to fail to compile filepos2z() in file.c

View File

@@ -3478,7 +3478,7 @@ clobber: clean
${RM} -rf .DS_Store; \
fi
${RM} -f func.show func.sort
${RM} -f outfile
${RM} -f outfile have_fpos.h
${V} echo '=-=-=-=-= ${MAKE_FILE} end of $@ rule =-=-=-=-='
# install everything

View File

@@ -1243,7 +1243,7 @@ EXT=
# The calc version in the form of x.y.z.w
#
VERSION= 2.15.0.4
VERSION= 2.15.0.5
# The calc major version in the form of x.y.z
#

View File

@@ -675,7 +675,7 @@ clean:
${RM} -f COPYING COPYING-LGPL questions
clobber: clean
${RM} -f ${BLT_HELP_FILES} full .all calc
${RM} -f ${BLT_HELP_FILES} full .all calc man usage
${RM} -f ${SINGULAR_FILES} ${DETAIL_CLONE}
-${Q} if [ -e .DS_Store ]; then \
echo ${RM} -rf .DS_Store; \
@@ -743,6 +743,14 @@ install: all
${RM} -f ${T}${HELPDIR}/md5; \
echo "removed old ${T}${HELPDIR}/md5"; \
fi;
-${Q} if [ -f "${T}${HELPDIR}/man" ]; then \
${RM} -f ${T}${HELPDIR}/man; \
echo "removed old ${T}${HELPDIR}/man"; \
fi;
-${Q} if [ -f "${T}${HELPDIR}/usage" ]; then \
${RM} -f ${T}${HELPDIR}/usage; \
echo "removed old ${T}${HELPDIR}/usage"; \
fi;
# Try to remove everything that was installed
#

76
hist.c
View File

@@ -73,6 +73,8 @@
#include "banned.h" /* include after system header <> includes */
#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
#if !defined(USE_READLINE)
E_FUNC FILE *curstream(void);
@@ -1472,37 +1474,69 @@ quit_calc(int UNUSED(ch))
* The readline/history libs do most of the dirty work for us, so we can
* replace hist_init() and hist_term() with dummies when using readline.
* For hist_getline() we have to add a newline that readline removed but
* calc expects. For hist_saveline(), we have to undo this. hist_getline()
* calc expects. For hist_saveline(), we have to undo this. hist_getline()
* also has to cope with the different memory management schemes of calc and
* readline.
* readline (pointer to target buffer passed to hist_getline() vs. returned
* malloc()ed buffer from readline()). While doing that, we also split
* multi-line strings potentially returned by readline() in case of
* bracketed paste mode even though its documentation promises to only return
* single lines. For details, see https://github.com/lcn2/calc/issues/138
* and https://lists.gnu.org/archive/html/bug-readline/2024-01/msg00000.html
*/
size_t
hist_getline(char *prompt, char *buf, size_t len)
{
char *line;
STATIC char *rlbuf, *rlcur;
buf[0] = '\0';
line = readline(prompt);
if (!line) {
switch (conf->ctrl_d) {
case CTRL_D_NEVER_EOF:
return 0;
case CTRL_D_VIRGIN_EOF:
case CTRL_D_EMPTY_EOF:
default:
quit_calc(0);
not_reached();
if (!rlbuf) {
rlbuf = rlcur = readline(prompt);
if (!rlbuf) {
buf[0] = '\0';
switch (conf->ctrl_d) {
case CTRL_D_NEVER_EOF:
return 0;
case CTRL_D_VIRGIN_EOF:
case CTRL_D_EMPTY_EOF:
default:
quit_calc(0);
not_reached();
}
}
}
strlcpy(buf, line, len);
buf[len - 2] = '\0';
len = strlen(buf);
buf[len] = '\n';
buf[len + 1] = '\0';
free(line);
return len + 1;
/* eol: pointer to trailing newline (if there is one) or \0 */
char *eol = strchr(rlcur, '\n');
if (!eol) {
eol = rlcur + strlen(rlcur);
}
/* len: length of line in target buffer including (possibly added)
* newline, truncated if buffer is too small. Note that we reduce
* the available buffer size by 1 so that we can safely add the
* newline below.
*/
len = MIN(len - 1, (size_t)(eol - rlcur + 1));
strlcpy(buf, rlcur, len);
/* make sure we have a newline and NUL */
buf[len - 1] = '\n';
buf[len] = '\0';
/* skip over newline in readline buffer */
if (*eol) {
eol++;
}
/* prepare for next invocation: point to next line or free readline
* buffer if we've reached EOL
*/
if (*eol) {
rlcur = eol;
} else {
free(rlbuf);
rlbuf = rlcur = NULL;
}
return len;
}

View File

@@ -64,7 +64,7 @@
#define MAJOR_VER 2 /* level 1: major library version */
#define MINOR_VER 15 /* level 2: minor library version */
#define MAJOR_PATCH 0 /* level 3: major software version level */
#define MINOR_PATCH 4 /* level 4: minor software version level */
#define MINOR_PATCH 5 /* level 4: minor software version level */
#endif /* !INCLUDE_VERSION_H*/