document prompt in shell script mode, fix man formatting, legacy awk

Documented unexpected behavior when calc is running in
"shell script mode" and the prompt builtin function is used
without the -p flag.  Updated help/prompt, help/unexpected
and the calc man page accordingly.

Unless calc is given the -p command line option, calc will reopen
stdin as /dev/null instead of just closing stdin.  This prevents
subsequent opens grabbing the 1st file descriptor.

Disable regress tests 4709, 4710, and 7763 because they print
multi-byte sequences, which are just fine for calc, the awk
used to evaluate the regression suite output in some legacy
systems report a "multibyte conversion failure".

Added a number of missing Makefile variables to the "make env" rule.

The man command is used to format the calc.1 man page into calc.usage.

The "help calc" command now prints the formatted calc man page (calc.usage).
The "help man" command now prints the formatted calc man page (calc.usage).
The "help usage" command now prints the formatted calc man page (calc.usage).

The file, calc.cat1, is formed by gzipping the calc.usage
formatted man page.  The calc.cat1 is installed as the calc
cat section 1 man page.

Updated the Copyright string in version.c to refer to
the COPYING file and the "help copying" command.

Added calc.cat1 to .gitignore.  Using "sort -d -u" to sort .gitignore content.

Avoiding use of modern [[ and ]] in Makefile for those legacy systems
whose shell do not support them.  *sigh*

Fixed the order of "help full" to match the order of topics listed
buy the "help help" command.

Sorted the halias[] help topics table in help.c using sort -d -u.
This commit is contained in:
Landon Curt Noll
2023-12-19 00:40:10 -08:00
parent d91e966f19
commit 54dd89dcf7
13 changed files with 372 additions and 205 deletions

43
.gitignore vendored
View File

@@ -1,17 +1,17 @@
# generic excluded patterns
#
# We sort the list below via: sort -u -f
# We sort the list below via: sort -d -u
#
*,v
*.BAK
*.dSYM/
*.exe
*.o.tmp
*.[oa]
*~
.*.swp
*.BAK
.DS_Store
core*
*.dSYM/
*.exe
*.[oa]
*.o.tmp
.*.swp
*,v
# files and directories created during the building of calc and other Makefile actions
#
@@ -19,50 +19,51 @@ core*
# not consider development source. Some other file(s) and/or programs
# generate these files.
#
# We sort the list below via: sort -u -f
# We sort the list below via: sort -d -u
#
.dynamic
.hsrc
.static
Makefile.our
NOTES
align32
align32.h
align32_tmp
arc4random_tmp
args.h
cal/.all
cal/test082.cal
calc
calc-static
calc.1
calc.cat1
calc.spec
calc-static
calc.usage
cal/test082.cal
charbit.h
chatbit
chk_c
conf.h
const_tmp
cscript/.all
cscript/4dsphere
cscript/README
cscript/.all
cscript/fproduct
cscript/mersenne
cscript/piforever
cscript/plus
cscript/powerterm
cscript/README
cscript/simple
cscript/square
custom/.all
custom/libcustcalc*
debug.out
.dynamic
endian
endian_calc.h
environ_tmp
errcode
errsym.h
fpos_tmp
fposval
fposval.h
fposval_tmp
fpos_tmp
func.show
func.sort
getpgid_tmp
@@ -127,6 +128,8 @@ have_urandom.h
have_ustat
have_ustat.h
have_varvs
help/COPYING
help/COPYING-LGPL
help/.all
help/binding
help/bindings
@@ -137,8 +140,6 @@ help/change
help/changes
help/contrib
help/copy
help/COPYING
help/COPYING-LGPL
help/cscript
help/custom_cal
help/errorcode
@@ -156,15 +157,14 @@ help/releases
help/resource
help/type
help/usage
.hsrc
libcalc.*
libcustcalc.*
ll_tmp
longbits
longbits.h
Makefile.our
memmv_tmp
newstr_tmp
NOTES
offscl_tmp
outfile
posscl_tmp
@@ -174,6 +174,7 @@ sample_many-static
sample_rand
sample_rand-static
statfs_tmp
.static
status.chk_c.h
strdup_tmp
tags

39
CHANGES
View File

@@ -23,6 +23,45 @@ The following are the changes from calc version 2.15.0.3 to date:
We now case the dest and src pointers to the proper type before
referencing and performing the assignment.
Documented unexpected behavior when calc is running in
"shell script mode" and the prompt builtin function is used
without the -p flag. Updated help/prompt, help/unexpected
and the calc man page accordingly.
Unless calc is given the -p command line option, calc will reopen
stdin as /dev/null instead of just closing stdin. This prevents
subsequent opens grabbing the 1st file descriptor.
Disable regress tests 4709, 4710, and 7763 because they print
multi-byte sequences, which are just fine for calc, the awk
used to evaluate the regression suite output in some legacy
systems report a "multibyte conversion failure".
Added a number of missing Makefile variables to the "make env" rule.
The man command is used to format the calc.1 man page into calc.usage.
The "help calc" command now prints the formatted calc man page (calc.usage).
The "help man" command now prints the formatted calc man page (calc.usage).
The "help usage" command now prints the formatted calc man page (calc.usage).
The file, calc.cat1, is formed by gzipping the calc.usage
formatted man page. The calc.cat1 is installed as the calc
cat section 1 man page.
Updated the Copyright string in version.c to refer to
the COPYING file and the "help copying" command.
Added calc.cat1 to .gitignore. Using "sort -d -u" to sort .gitignore content.
Avoiding use of modern [[ and ]] in Makefile for those legacy systems
whose shell do not support them. *sigh*
Fixed the order of "help full" to match the order of topics listed
buy the "help help" command.
Sorted the halias[] help topics table in help.c using sort -d -u.
The following are the changes from calc version 2.15.0.1 to 2.15.0.2:

122
Makefile
View File

@@ -321,14 +321,17 @@ STATIC_FIRST_TARGETS= ${LICENSE} .static
# late targets - things needed after the main build phase is complete
#
LATE_TARGETS= calc.1 calc.usage \
LATE_TARGETS= calc.1 calc.usage calc.cat1 \
cal/.all help/.all help/builtin help/errorcodes \
cscript/.all
# calc tools - tools used by the maintainers of the calc source base
#
# trailblank - find trailing blanks and other file format picky issues
# update_ver - update version numbers in Makefile.config
# Calc supplied tools:
#
# TRAILBLANK - find trailing blanks and other file format picky issues
# UPDATE_VER - update version numbers in Makefile.config
# CALC_TOOLS - the complete list of calc supplied tools
#
TRAILBLANK= trailblank
UPDATE_VER= update_ver
@@ -529,15 +532,19 @@ calc.1: calc.man ${MK_SET}
-e 's,:\([/.~]\),:\\:\1,g' < calc.man > calc.1
${Q} echo calc.1 formed
calc.usage: calc.1 ${MK_SET}
calc.usage: calc.1
${Q} echo forming $@ from calc.1
${RM} -f $@
${Q} echo forming calc.usage from calc.1
${Q} if [ -z "${NROFF}" ]; then \
LESSCHARSET=iso8859 ${CALCPAGER} calc.1; \
else \
${NROFF} -man calc.1; \
fi 2>&1 | ${GREP} -E -v 'cannot adjust line' | ${COL} -b > $@
${Q} echo calc.usage formed
${MAN} ./calc.1 > $@
${CHMOD} 0444 $@
${Q} echo $@ formed
calc.cat1: calc.usage
${Q} echo forming $@ from calc.usage
${RM} -f $@
${GZIP} --best -f -c calc.usage > $@
${CHMOD} 0444 $@
${Q} echo $@ formed
##
@@ -563,7 +570,7 @@ sample_many${EXT}: sample_many.o ${CALC_DYNAMIC_LIBS} ${MK_SET}
###
hist.o: hist.c ${MK_SET}
${CC} ${CFLAGS} ${TERMCONTROL} ${USE_READLINE} ${READLINE_INCLUDE} \
${CC} ${CFLAGS} -Wno-strict-prototypes ${TERMCONTROL} ${USE_READLINE} ${READLINE_INCLUDE} \
-c hist.c
seed.o: seed.c ${MK_SET}
@@ -2846,23 +2853,25 @@ env:
@echo 'BUILD_C_SRC=${BUILD_C_SRC}'; echo ''
@echo 'BUILD_H_SRC=${BUILD_H_SRC}'; echo ''
@echo 'BYTE_ORDER=${BYTE_ORDER}'; echo ''
@echo 'CALC_BYTE_ORDER=${CALC_BYTE_ORDER}'; echo ''
@echo 'CALC_CHARBIT=${CALC_CHARBIT}'; echo ''
@echo 'CALC_DYNAMIC_LIBS=${CALC_DYNAMIC_LIBS}'; echo ''
@echo 'CALC_ENV=${CALC_ENV}'; echo ''
@echo 'CALC_INCDIR=${CALC_INCDIR}'; echo ''
@echo 'CALCLIBLIST=${CALCLIBLIST}'; echo ''
@echo 'CALCOBJS=${CALCOBJS}'; echo ''
@echo 'CALCPAGER=${CALCPAGER}'; echo ''
@echo 'CALCPATH=${CALCPATH}'; echo ''
@echo 'CALCRC=${CALCRC}'; echo ''
@echo 'CALCSRC=${CALCSRC}'; echo ''
@echo 'CALC_DYNAMIC_LIBS=${CALC_DYNAMIC_LIBS}'; echo ''
@echo 'CALC_ENV=${CALC_ENV}'; echo ''
@echo 'CALC_INCDIR=${CALC_INCDIR}'; echo ''
@echo 'CALC_SHAREDIR=${CALC_SHAREDIR}'; echo ''
@echo 'CALCSRC=${CALCSRC}'; echo ''
@echo 'CALC_STATIC_LIBS=${CALC_STATIC_LIBS}'; echo ''
@echo 'CALC_TOOLS=${CALC_TOOLS}'; echo ''
@echo 'CAT=${CAT}'; echo ''
@echo 'CATDIR=${CATDIR}'; echo ''
@echo 'CATEXT=${CATEXT}'; echo ''
@echo 'CATMODE=${CATMODE}'; echo ''
@echo 'CC=${CC}'; echo ''
@echo 'CCBAN=${CCBAN}'; echo ''
@echo 'CC=${CC}'; echo ''
@echo 'CCMISC=${CCMISC}'; echo ''
@echo 'CCOPT=${CCOPT}'; echo ''
@echo 'CCWARN=${CCWARN}'; echo ''
@@ -2871,32 +2880,36 @@ env:
@echo 'CHMOD=${CHMOD}'; echo ''
@echo 'CMP=${CMP}'; echo ''
@echo 'CO=${CO}'; echo ''
@echo 'COL=${COL}'; echo ''
@echo 'COMMON_ADD=${COMMON_ADD}'; echo ''
@echo 'COMMON_CFLAGS=${COMMON_CFLAGS}'; echo ''
@echo 'COMMON_LDFLAGS=${COMMON_LDFLAGS}'; echo ''
@echo 'CONFIG_MKF=${CONFIG_MKF}'; echo ''
@echo 'CP=${CP}'; echo ''
@echo 'CSCRIPT_TARGETS=${CSCRIPT_TARGETS}'; echo ''
@echo 'C_SRC=${C_SRC}'; echo ''
@echo 'CTAGS=${CTAGS}'; echo ''
@echo 'CUSTOMCALDIR=${CUSTOMCALDIR}'; echo ''
@echo 'CUSTOMHELPDIR=${CUSTOMHELPDIR}'; echo ''
@echo 'CUSTOMINCDIR=${CUSTOMINCDIR}'; echo ''
@echo 'C_SRC=${C_SRC}'; echo ''
@echo 'DATE=${DATE}'; echo ''
@echo 'DEBUG=${DEBUG}'; echo ''
@echo 'DEFAULT_LIB_INSTALL_PATH=${DEFAULT_LIB_INSTALL_PATH}'; echo ''
@echo 'DEV_BITS=${DEV_BITS}'; echo ''
@echo 'DIFF=${DIFF}'; echo ''
@echo 'DISTLIST=${DISTLIST}'; echo ''
@echo 'E=${E}'; echo ''
@echo 'DYNAMIC_FIRST_TARGETS=${DYNAMIC_FIRST_TARGETS}'; echo ''
@echo 'EARLY_TARGETS=${EARLY_TARGETS}'; echo ''
@echo 'ECHON=${ECHON}'; echo ''
@echo 'E=${E}'; echo ''
@echo 'EXT=${EXT}'; echo ''
@echo 'EXTRA_CFLAGS=${EXTRA_CFLAGS}'; echo ''
@echo 'EXTRA_LDFLAGS=${EXTRA_LDFLAGS}'; echo ''
@echo 'FMT=${FMT}'; echo ''
@echo 'FPOS_BITS=${FPOS_BITS}'; echo ''
@echo 'FPOS_POS_BITS=${FPOS_POS_BITS}'; echo ''
@echo 'FSANITIZE=${FSANITIZE}'; echo ''
@echo 'GREP=${GREP}'; echo ''
@echo 'H=${H}'; echo ''
@echo 'GZIP=${GZIP}'; echo ''
@echo 'HAVE_ARC4RANDOM=${HAVE_ARC4RANDOM}'; echo ''
@echo 'HAVE_CONST=${HAVE_CONST}'; echo ''
@echo 'HAVE_ENVIRON=${HAVE_ENVIRON}'; echo ''
@@ -2924,11 +2937,11 @@ env:
@echo 'HAVE_STRLCPY=${HAVE_STRLCPY}'; echo ''
@echo 'HAVE_SYS_MOUNT_H=${HAVE_SYS_MOUNT_H}'; echo ''
@echo 'HAVE_SYS_PARAM_H=${HAVE_SYS_PARAM_H}'; echo ''
@echo 'HAVE_SYS_TIMES_H=${HAVE_SYS_TIMES_H}'; echo ''
@echo 'HAVE_SYS_TIME_H=${HAVE_SYS_TIME_H}'; echo ''
@echo 'HAVE_SYS_TIMES_H=${HAVE_SYS_TIMES_H}'; echo ''
@echo 'HAVE_SYS_VFS_H=${HAVE_SYS_VFS_H}'; echo ''
@echo 'HAVE_TIMES_H=${HAVE_TIMES_H}'; echo ''
@echo 'HAVE_TIME_H=${HAVE_TIME_H}'; echo ''
@echo 'HAVE_TIMES_H=${HAVE_TIMES_H}'; echo ''
@echo 'HAVE_UID_T=${HAVE_UID_T}'; echo ''
@echo 'HAVE_UNISTD_H=${HAVE_UNISTD_H}'; echo ''
@echo 'HAVE_UNUSED=${HAVE_UNUSED}'; echo ''
@@ -2936,6 +2949,7 @@ env:
@echo 'HAVE_USTAT=${HAVE_USTAT}'; echo ''
@echo 'HAVE_VSNPRINTF=${HAVE_VSNPRINTF}'; echo ''
@echo 'HELPDIR=${HELPDIR}'; echo ''
@echo 'H=${H}'; echo ''
@echo 'HOSTNAME=${HOSTNAME}'; echo ''
@echo 'H_SRC=${H_SRC}'; echo ''
@echo 'ICFLAGS=${ICFLAGS}'; echo ''
@@ -2946,46 +2960,48 @@ env:
@echo 'LATE_TARGETS=${LATE_TARGETS}'; echo ''
@echo 'LCC=${LCC}'; echo ''
@echo 'LDCONFIG=${LDCONFIG}'; echo ''
@echo 'LDFLAGS=${LDFLAGS}'; echo ''
@echo 'LD_DEBUG=${LD_DEBUG}'; echo ''
@echo 'LDFLAGS=${LDFLAGS}'; echo ''
@echo 'LD_SHARE=${LD_SHARE}'; echo ''
@echo 'LIBCALC_SHLIB=${LIBCALC_SHLIB}'; echo ''
@echo 'LIBCUSTCALC_SHLIB=${LIBCUSTCALC_SHLIB}'; echo ''
@echo 'LIBDIR=${LIBDIR}'; echo ''
@echo 'LIB_EXT=${LIB_EXT}'; echo ''
@echo 'LIB_EXT_VER=${LIB_EXT_VER}'; echo ''
@echo 'LIB_EXT_VERSION=${LIB_EXT_VERSION}'; echo ''
@echo 'LIB_H_SRC=${LIB_H_SRC}'; echo ''
@echo 'LIBOBJS=${LIBOBJS}'; echo ''
@echo 'LIBSRC=${LIBSRC}'; echo ''
@echo 'LIB_H_SRC=${LIB_H_SRC}'; echo ''
@echo 'LICENSE=${LICENSE}'; echo ''
@echo 'LN=${LN}'; echo ''
@echo 'LOCAL_MKF=${LOCAL_MKF}'; echo ''
@echo 'LONG_BITS=${LONG_BITS}'; echo ''
@echo 'MAKE=${MAKE}'; echo ''
@echo 'LS=${LS}'; echo ''
@echo 'MAKEDEPEND=${MAKEDEPEND}'; echo ''
@echo 'MAKE_FILE=${MAKE_FILE}'; echo ''
@echo 'MAKE=${MAKE}'; echo ''
@echo 'MAN=${MAN}'; echo ''
@echo 'MANDIR=${MANDIR}'; echo ''
@echo 'MANEXT=${MANEXT}'; echo ''
@echo 'MANMAKE=${MANMAKE}'; echo ''
@echo 'MANMODE=${MANMODE}'; echo ''
@echo 'MINGW=${MINGW}'; echo ''
@echo 'MKDIR=${MKDIR}'; echo ''
@echo 'MK_SET=${MK_SET}'; echo ''
@echo 'MV=${MV}'; echo ''
@echo 'NROFF=${NROFF}'; echo ''
@echo 'NROFF_ARG=${NROFF_ARG}'; echo ''
@echo 'OBJS=${OBJS}'; echo ''
@echo 'OFF_T_BITS=${OFF_T_BITS}'; echo ''
@echo 'OSNAME=${OSNAME}'; echo ''
@echo 'PHONY=${PHONY}'; echo ''
@echo 'PREFIX=${PREFIX}'; echo ''
@echo 'PURIFY=${PURIFY}'; echo ''
@echo 'PWD=${PWD}'; echo ''
@echo 'PWDCMD=${PWDCMD}'; echo ''
@echo 'PWD=${PWD}'; echo ''
@echo 'Q=${Q}'; echo ''
@echo 'RANLIB=${RANLIB}'; echo ''
@echo 'READLINE_EXTRAS=${READLINE_EXTRAS}'; echo ''
@echo 'READLINE_INCLUDE=${READLINE_INCLUDE}'; echo ''
@echo 'READLINE_LIB=${READLINE_LIB}'; echo ''
@echo 'RM=${RM}'; echo ''
@echo 'RMDIR=${RMDIR}'; echo ''
@echo 'S=${S}'; echo ''
@echo 'RM=${RM}'; echo ''
@echo 'SAMPLE_C_SRC=${SAMPLE_C_SRC}'; echo ''
@echo 'SAMPLE_H_SRC=${SAMPLE_H_SRC}'; echo ''
@echo 'SAMPLE_OBJ=${SAMPLE_OBJ}'; echo ''
@@ -2996,17 +3012,23 @@ env:
@echo 'SED=${SED}'; echo ''
@echo 'SHELL=${SHELL}'; echo ''
@echo 'SORT=${SORT}'; echo ''
@echo 'SPLINT=${SPLINT}'; echo ''
@echo 'SPLINT_OPTS=${SPLINT_OPTS}'; echo ''
@echo 'SPLINT=${SPLINT}'; echo ''
@echo 'S=${S}'; echo ''
@echo 'STATIC_FIRST_TARGETS=${STATIC_FIRST_TARGETS}'; echo ''
@echo 'STRIP=${STRIP}'; echo ''
@echo 'SYM_DYNAMIC_LIBS=${SYM_DYNAMIC_LIBS}'; echo ''
@echo 'T=${T}'; echo ''
@echo 'TARGETS=${TARGETS}'; echo ''
@echo 'TAIL=${TAIL}'; echo ''
@echo 'TARGET_MKF=${TARGET_MKF}'; echo ''
@echo 'TARGETS=${TARGETS}'; echo ''
@echo 'TEE=${TEE}'; echo ''
@echo 'TERMCONTROL=${TERMCONTROL}'; echo ''
@echo 'TOUCH=${TOUCH}'; echo ''
@echo 'TRAILBLANK=${TRAILBLANK}'; echo ''
@echo 'TRUE=${TRUE}'; echo ''
@echo 'T=${T}'; echo ''
@echo 'UNAME=${UNAME}'; echo ''
@echo 'UPDATE_VER=${UPDATE_VER}'; echo ''
@echo 'USE_READLINE=${USE_READLINE}'; echo ''
@echo 'UTIL_C_SRC=${UTIL_C_SRC}'; echo ''
@echo 'UTIL_FILES=${UTIL_FILES}'; echo ''
@@ -3014,8 +3036,9 @@ env:
@echo 'UTIL_OBJS=${UTIL_OBJS}'; echo ''
@echo 'UTIL_PROGS=${UTIL_PROGS}'; echo ''
@echo 'UTIL_TMP=${UTIL_TMP}'; echo ''
@echo 'V=${V}'; echo ''
@echo 'VERSION=${VERSION}'; echo ''
@echo 'VER=${VER}'; echo ''
@echo 'V=${V}'; echo ''
@echo 'WNO_ERROR_LONG_LONG=${WNO_ERROR_LONG_LONG}'; echo ''
@echo 'WNO_IMPLICT=${WNO_IMPLICT};' echo ''
@echo 'WNO_LONG_LONG=${WNO_LONG_LONG}'; echo ''
@@ -3201,9 +3224,9 @@ prep:
${Q}echo
${MAKE} -s depend
${Q}echo
@if [[ -f ${MAKE_FILE}.bak ]]; then echo ${MAKE_FILE}.bak exists 1>&2; exit 1; fi
@if [[ -f cscript/${MAKE_FILE}.bak ]]; then echo cscript/${MAKE_FILE}.bak exists 1>&2; exit 2; fi
@if [[ -f custom/${MAKE_FILE}.bak ]]; then echo custom/${MAKE_FILE}.bak exists 1>&2; exit 3; fi
@if [ -f ${MAKE_FILE}.bak ]; then echo ${MAKE_FILE}.bak exists 1>&2; exit 1; fi
@if [ -f cscript/${MAKE_FILE}.bak ]; then echo cscript/${MAKE_FILE}.bak exists 1>&2; exit 2; fi
@if [ -f custom/${MAKE_FILE}.bak ]; then echo custom/${MAKE_FILE}.bak exists 1>&2; exit 3; fi
${Q}echo '=-=-=-=-=-= end of ${MAKE} depend =-=-=-=-=-='
${Q}echo
${Q}echo '=-=-=-=-=-= start of ${MAKE} testfuncsort =-=-=-=-=-='
@@ -3415,7 +3438,7 @@ clobber: clean
${RM} -f *.u
${RM} -f libcalc.a
${RM} -f libcustcalc.a
${RM} -f calc.1 calc.usage
${RM} -f calc.1 calc.cat1
${RM} -f calc.pixie calc.rf calc.Counts calc.cord
${RM} -f gen_h Makefile.bak tmp.patch
${RM} -rf skel
@@ -3751,7 +3774,7 @@ install: ${LIB_H_SRC} ${BUILD_H_SRC} calc.1 all custom/Makefile
echo "removed old ${T}${CALC_INCDIR}/string.h"; \
fi; \
done
-${Q} if [ -z "${MANDIR}" ]; then \
-${Q} if [ -z "${MANDIR}" || ! -s calc.1 ]; then \
${TRUE}; \
else \
if ${CMP} -s calc.1 ${T}${MANDIR}/calc.${MANEXT}; then \
@@ -3765,24 +3788,17 @@ install: ${LIB_H_SRC} ${BUILD_H_SRC} calc.1 all custom/Makefile
echo "installed ${T}${MANDIR}/calc.${MANEXT}"; \
fi; \
fi
-${Q} if [ -z "${CATDIR}" ]; then \
-${Q} if [ -z "${CATDIR}" || ! -s calc.cat1 ]; then \
${TRUE}; \
else \
if ${CMP} -s calc.1 ${T}${MANDIR}/calc.${MANEXT}; then \
if ${CMP} -s calc.cat1 ${T}${CATDIR}/calc.${MANEXT}; then \
${TRUE}; \
else \
if [ -n "${NROFF}" ]; then \
${RM} -f ${T}${CATDIR}/calc.${CATEXT}.new; \
${NROFF} ${NROFF_ARG} calc.1 > \
${T}${CATDIR}/calc.${CATEXT}.new; \
${CHMOD} ${MANMODE} ${T}${MANDIR}/calc.${CATEXT}.new; \
${CP} -f calc.cat1 ${T}${CATDIR}/calc.${CATEXT}.new; \
${MV} -f ${T}${CATDIR}/calc.${CATEXT}.new \
${T}${CATDIR}/calc.${CATEXT}; \
echo "installed ${T}${CATDIR}/calc.${CATEXT}"; \
elif [ -x "${MANNAME}" ]; then \
echo "${MANMAKE} calc.1 ${T}${CATDIR}"; \
${MANMAKE} calc.1 ${T}${CATDIR}; \
fi; \
fi; \
fi
${V} # NOTE: misc install cleanup

View File

@@ -997,9 +997,6 @@ endif # ($(target),Darwin)
#
# Use CATDIR= to disable installation of the calc cat (formatted) page.
#
# NOTE: If CATDIR is non-empty, then one should have either the
# ${NROFF} executable and/or the ${MANMAKE} executable.
#
CATDIR=
#CATDIR= ${PREFIX}/man/cat1
#CATDIR= ${PREFIX}/catman/cat1
@@ -1026,36 +1023,6 @@ CATEXT= 1
#CATEXT= 0
#CATEXT= l
# how to format a man page
#
# If CATDIR is non-empty, then
#
# If NROFF is non-empty, then
#
# ${NROFF} ${NROFF_ARG} calc.1 > ${CATDIR}/calc.${CATEXT}
# is used to build and install the cat page
#
# else (NROFF is empty)
#
# ${MANMAKE} calc.1 ${CATDIR}
# is used to build and install the cat page
# else
#
# The cat page is not built or installed
#
# If in doubt and you don't want to fool with man pages, set MANDIR
# and CATDIR to empty and ignore the NROFF, NROFF_ARG and MANMAKE
# lines below.
#
#NROFF= nroff
NROFF=
#NROFF= groff
NROFF_ARG= -man
#NROFF_ARG= -mandoc
MANMAKE= ${PREFIX}/bin/manmake
#MANMAKE= manmake
MANMODE= 0444
CATMODE= 0444
# By default, custom builtin functions may only be executed if calc
# is given the -C option. This is because custom builtin functions
@@ -1296,13 +1263,13 @@ CAT= cat
CHMOD= chmod
CMP= cmp
CO= co
COL= col
CP= cp
CTAGS= ctags
DATE= date
DIFF= diff
FMT= fmt
GREP= grep
GZIP= gzip
HOSTNAME= hostname
LANG= C
LDCONFIG= ldconfig
@@ -1310,6 +1277,7 @@ LN= ln
LS= ls
MAKE= make
MAKEDEPEND= makedepend
MAN= man
MKDIR= mkdir
MV= mv
PWDCMD= pwd
@@ -1321,8 +1289,8 @@ SORT= sort
SPLINT= splint
SPLINT_OPTS=
STRIP= strip
TEE= tee
TAIL= tail
TEE= tee
TOUCH= touch
TRUE= true
UNAME= uname

View File

@@ -4879,8 +4879,9 @@ define test_charset()
vrfy("\123" == char(0123), '4706: "\\123" == char(0123)');
vrfy("\123\124" == "ST", '4707: "\\123\\124" == "ST"');
vrfy("\311" == char(201), '4708: "\\311" == char(201)');
vrfy("\119" == "\t9", '4709: "\\119" == "\t9"');
vrfy("\765" == "\365", '4710: "\\765" == "\365"');
/* NOTE: We skip non-ASCII to avoid problems with old awk that cannot handle them */
/* vrfy("\119" == "\t9", '4709: "\\119" == "\t9"'); */
/* vrfy("\765" == "\365", '4710: "\\765" == "\365"'); */
vrfy("\x61" == "a", '4711: "\\x61" == "a"');
vrfy("\x73" == "s", '4712: "\\x73" == "s"');
vrfy("\xea" == char(234), '4713: "\\xea" == char(234)');
@@ -8191,7 +8192,8 @@ define test_newstring()
vrfy(A == "A\255gdef", '7761: A == "A\\255gdef"');
setbit(A, 16, 0);
print '7762: setbit(A, 16, 0);';
vrfy(A == "A\255fdef", '7763: A == "A\255fdef"');
/* NOTE: We skip non-ASCII to avoid problems with old awk that cannot handle them */
/* vrfy(A == "A\255fdef", '7763: A == "A\255fdef"'); */
q = "curds" " and " "whey";
print '7764: q = "curds" " and " "whey"';

4
calc.c
View File

@@ -543,8 +543,8 @@ main(int argc, char **argv)
cmdbuf[cmdlen++] = '\n';
cmdbuf[cmdlen] = '\0';
if (p_flag != true) {
if (fclose(stdin)) {
perror("main(): fclose(stdin) failed:");
if (freopen("/dev/null", "r", stdin) == NULL) {
perror("in main: freopen(\"/dev/null\", \"r\", stdin) failed:");
}
stdin_closed = true;
}

View File

@@ -470,6 +470,24 @@ The
flag overrides
.BR \-i .
.sp 1
When running calc as a shell script (see
.B "SHELL SCRIPT MODE"
for details), calc will close standard input (stdin)
during startup
.B UNLESS
the
.B \-p
flag is given on the command line.
When calc is running in
.BR "shell script mode" ,
shell scripts that call the
.BR prompt (str)
builtin will not work properly (the prompt builtin
will always fail) unless the
.B \-p
flag is given on the command line.
.TP
.B \-q
Disable the reading of the startup scripts.
@@ -651,7 +669,9 @@ echo chongo was here | calc \-i 'print fgetline(files(0));'
.fi
.in -5n
.sp 1
This is because without \-p, the interactive parser, in an effort
This is because without
.BR \-p ,
the interactive parser, in an effort
to parse interactive commands, flushes data on standard input.
.PP
@@ -932,6 +952,67 @@ whereas
.sp 1
will not.
.sp 1
By default, using calc startup in
.BR "shell script mode" ,
calc will close standard input (stdin).
Thus builtin functions such as
.BR prompt (str)
will fail (return a null value).
Calc shell scripts that call the
.BR prompt (str)
builtin will not work properly (the prompt builtin
will always fail and return a null value) unless the
.B \-p
flag is given on the command line.
.sp 1
The following shell script will always print "got null" because
stdin will be closed by calc during startup:
.sp 1
.in +5n
.nf
#!/usr/bin/calc \-q \-f
# The prompt will ALWAYS FAIL and return a null value
n = prompt("Test> ");
if (isnull(n)) {
print("got null");
} else {
print("got " + n);
}
.fi
.in -5n
.sp 1
However the following shell script (note the
.B \-p
before the
.B \-f
in the 1st line) will be interactive, prompt with "Test> " and print
the "got" result as expected:
.sp 1
.in +5n
.nf
#!/usr/bin/calc \-q \-p \-f
n = prompt("Test> ");
if (isnull(n)) {
print("got null");
} else {
print("got " + n);
}
.fi
.in -5n
.sp 1
Note in the example above, the
.B \-p
flag must be given before the final
.B \-f
command line flag.
.PP
.SH DATA TYPES

39
help.c
View File

@@ -56,38 +56,41 @@ STATIC struct help_alias {
char *topic;
char *filename;
} halias[] = {
/* We sort the list below via: sort -d -u */
{"=", "address"},
{"->", "arrow"},
{"=", "assign"},
{"*", "dereference"},
{".", "oldvalue"},
{"%", "mod"},
{"//", "quo"},
{".", "oldvalue"},
{"#", "pound"},
{"calc", "help"},
{"//", "quo"},
{"COPYING_LGPL", "COPYING-LGPL"},
{"COPYLEFT", "copyright"},
{"COPYRIGHT", "copyright"},
{"Copyleft", "copyright"},
{"Copyright", "copyright"},
{"abort", "command"},
{"cd", "command"},
{"copy", "blkcpy"},
{"copying", "COPYING"},
{"copying-lgpl", "COPYING-LGPL"},
{"copying_lgpl", "COPYING-LGPL"},
{"COPYING_LGPL", "COPYING-LGPL"},
{"Copyright", "copyright"},
{"COPYRIGHT", "copyright"},
{"Copyleft", "copyright"},
{"COPYLEFT", "copyright"},
{"define", "command"},
{"read", "command"},
{"write", "command"},
{"quit", "command"},
{"exit", "command"},
{"abort", "command"},
{"cd", "command"},
{"show", "command"},
{"stdlib", "resource"},
{"question", "questions"},
{"dm2d", "dms2d"},
{"exit", "command"},
{"gm2g", "gms2g"},
{"hm2d", "hms2d"},
{"man", "calc"},
{"question", "questions"},
{"quit", "command"},
{"read", "command"},
{"release", "releases"},
{"show", "command"},
{"stdlib", "resource"},
{"usage", "calc"},
{"write", "command"},
/* MUST BE LAST! */
{NULL, NULL}
};

View File

@@ -118,44 +118,33 @@ V=@:
# Files managed by this Makefile #
##################################
STD_HELP_FILES_1= intro overview help
STD_HELP_FILES_1= intro overview calc
STD_HELP_FILES_2= assoc
BLT_HELP_FILES_3= builtin man
STD_HELP_FILES_4= command config custom define environment expression
BLT_HELP_FILES_3= builtin
STD_HELP_FILES_4= command config custom define environment
BLT_HELP_FILES_5= errorcodes
STD_HELP_FILES_6= file history interrupt list mat
STD_HELP_FILES_6= expression file history interrupt list mat
# because obj is built special (due to confusion with it as
# a symlink for some built environments, we treat obj specially
# and call it obj.file
#
SPECIAL_HELP_7= obj.file
STD_HELP_FILES_8= operator statement
STD_HELP_FILES_8= operator
BLT_HELP_FILES_9= resource
STD_HELP_FILES_10= script statement types unexpected variable
STD_HELP_FILES_10= types script
BLT_HELP_FILES_10a= usage cscript
STD_HELP_FILES_10b= unexpected variable
BLT_HELP_FILES_11= bindings custom_cal libcalc new_custom resource
BLT_HELP_FILES_11= bindings custom_cal libcalc new_custom cscript
STD_HELP_FILES_12= archive
BLT_HELP_FILES_13= bugs changes contrib
STD_HELP_FILES_14= todo wishlist
BLT_HELP_FILES_13= bugs changes
STD_HELP_FILES_15= credit
# copyright is printed by help.c is from the Copyright string found in version.c
BLT_HELP_FILES_16= COPYING COPYING-LGPL questions releases
STD_HELP_FILES_14= credit
BLT_HELP_FILES_14= contrib COPYING COPYING-LGPL questions releases
STD_HELP_FILES_15= wishlist todo
STD_HELP_FILES_17= help
# These files are used in the following order to construct full
#
@@ -164,19 +153,18 @@ FULL_HELP_FILES= ${STD_HELP_FILES_1} ${STD_HELP_FILES_2} \
${BLT_HELP_FILES_5} ${STD_HELP_FILES_6} \
${SPECIAL_HELP_7} ${STD_HELP_FILES_8} \
${BLT_HELP_FILES_9} ${STD_HELP_FILES_10} \
${BLT_HELP_FILES_10a} ${STD_HELP_FILES_10b} \
${BLT_HELP_FILES_11} ${STD_HELP_FILES_12} \
${BLT_HELP_FILES_13} ${STD_HELP_FILES_14} \
${BLT_HELP_FILES_14} ${STD_HELP_FILES_15}
${STD_HELP_FILES_15} ${BLT_HELP_FILES_16} \
${STD_HELP_FILES_17}
# These full files are those who are not built or constructed
#
STD_HELP_FILES= ${STD_HELP_FILES_1} ${STD_HELP_FILES_2} \
${STD_HELP_FILES_4} ${STD_HELP_FILES_6} \
${STD_HELP_FILES_8} ${STD_HELP_FILES_10} \
${STD_HELP_FILES_10b} \
${STD_HELP_FILES_12} ${STD_HELP_FILES_14} \
${STD_HELP_FILES_15}
${STD_HELP_FILES_15} ${STD_HELP_FILES_17}
# These full files are those who are built by this Makefile
#
@@ -184,10 +172,8 @@ STD_HELP_FILES= ${STD_HELP_FILES_1} ${STD_HELP_FILES_2} \
# because of problems with its name.
#
BLT_HELP_FILES= ${BLT_HELP_FILES_3} ${BLT_HELP_FILES_5} \
${BLT_HELP_FILES_9} \
${BLT_HELP_FILES_10a} \
${BLT_HELP_FILES_11} ${BLT_HELP_FILES_13} \
${BLT_HELP_FILES_14}
${BLT_HELP_FILES_9} ${BLT_HELP_FILES_11} \
${BLT_HELP_FILES_13} ${BLT_HELP_FILES_16}
# The detailed list of help files to install
#
@@ -382,7 +368,7 @@ errorcodes: ../errcode${EXT}
${TRUE}; \
fi
usage: ../calc.usage
calc: ../calc.usage
${RM} -f $@
${CP} ../calc.usage $@
${CHMOD} 0444 $@
@@ -433,18 +419,6 @@ copy: blkcpy
${TRUE}; \
fi
man: help
${RM} -f $@
${CP} help $@
${CHMOD} 0444 $@
-@if [ -z "${Q}" ]; then \
echo ''; \
echo '=-=-= skipping the ${CAT} of help/$@ =-=-='; \
echo ''; \
else \
${TRUE}; \
fi
COPYING: ../COPYING
${RM} -f $@
${CP} ../COPYING $@

View File

@@ -5,7 +5,7 @@ following topics:
----- -----------
intro introduction to calc
overview overview of calc
help this file
calc calc man page, how to invoke the calc command
assoc using associations
builtin builtin functions
@@ -23,18 +23,17 @@ following topics:
mat using matrices
obj user defined data types
operator math, relational, logic and variable access operators
resource standard calc resource files
script using calc shell scripts
statement flow control and declaration statements
types builtin data types
unexpected unexpected syntax/usage surprises for C programmers
usage how to invoke the calc command
variable variables and variable declarations
bindings input & history character bindings
custom_cal information about custom calc resource files
libcalc using the arbitrary precision routines in a C program
new_custom information about how to add new custom functions
resource standard calc resource files
script using calc shell scripts
cscript info on the calc shell scripts supplied with calc
archive where to get the latest versions of calc
@@ -51,6 +50,7 @@ following topics:
questions how to ask simple general question about calc
release on calc versions and releases
help this file
full all of the above (in the above order)
For example:

View File

@@ -15,6 +15,39 @@ DESCRIPTION
read from the input; the string formed by the characters in the line
(other than the newline) is returned as the value of prompt().
Be careful when using prompt(str) while calc is being used as a
shell script. Unless calc is run with the -p command line option,
the prompt builtin will fail and return null. This is because when
calc is running as a shell script, calc will close stdin run in in
a non-interactive mode.
The following shell script will always print "got null" because
stdin will be closed by calc during startup:
#!/usr/bin/calc -q -f
# The prompt will ALWAYS FAIL and return a null value
n = prompt("Test> ");
if (isnull(n)) {
print("got null");
} else {
print("got " + n);
}
However the following shell script (note the -p before the -f in
the 1st line) will be interactive, prompt with "Test> " and print
the "got" result as expected:
#!/usr/bin/calc -q -p -f
n = prompt("Test> ");
if (isnull(n)) {
print("got null");
} else {
print("got " + n);
}
EXAMPLE
; x = prompt("? ");
? 273
@@ -35,9 +68,9 @@ LINK LIBRARY
none
SEE ALSO
fgetfield, fgetline, fgetstr
command, fgetfield, fgetline, fgetstr, unexpected
## Copyright (C) 1999-2006 Landon Curt Noll
## Copyright (C) 1999,2023 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -563,6 +563,7 @@ Unexpected
; print sin(d2r(30))
0.5
* operator has has a higher precedence than <<
==============================================
@@ -570,6 +571,49 @@ Unexpected
So 3 << 2*5 evaluates to 3072 in C, whereas 3 << 2*5 evaluates to 60 in calc.
prompt builtin returns null in calc shell scripts unless -p is used
===================================================================
Be careful when using prompt(str) while calc is being used as a
shell script. Unless calc is run with the -p command line option,
the prompt builtin will fail and return null. This is because when
calc is running as a shell script, calc will close stdin run in in
a non-interactive mode.
The following shell script will always print "got null" because
stdin will be closed by calc during startup:
#!/usr/bin/calc -q -f
n = prompt("Test> ");
if (isnull(n)) {
print("got null");
} else {
print("got " + n);
}
However the following shell script (note the -p before the -f in
the 1st line) will be interactive, prompt with "Test> " and print
the "got" result as expected:
#!/usr/bin/calc -q -p -f
n = prompt("Test> ");
if (isnull(n)) {
print("got null");
} else {
print("got " + n);
}
Note in the example above, the -p flag must be given before the
final -f command line flag.
A similar problem will occur if the calc shell script attempts
to read from standard input (stdin), unless the -p flag is used.
See "SHELL SCRIPT MODE" in the calc man page for more information
about -p and about the "shell script mode".
## Copyright (C) 1999-2007,2014,2017,2021,2023 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under

View File

@@ -80,7 +80,13 @@ char *Copyright = "\n"
"\n"
"Calc is open software; you can redistribute it and/or modify it under\n"
"the terms of the version 2.1 of the GNU Lesser General Public License\n"
"as published by the Free Software Foundation.\n";
"as published by the Free Software Foundation.\n"
"\n"
"Please see the file COPYING, or use the calc command:\n"
"\n"
"\thelp copying\n"
"\n"
"for important copyright and license information!\n";
char *Usability = "\n"
"Calc is distributed in the hope that it will be useful, but WITHOUT\n"
"ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n"