Compare commits

..

11 Commits

Author SHA1 Message Date
Landon Curt Noll
25dcd8cb80 Release v2.14.1.1
The following are the changes in this release:

    Added a few remarks on calc version numbers to version.c.

    Fixed how fposval.h is built.  On a number of systems, the fposval.c
    file failed to compile incorrectly.  This caused problems for systems in
    which fposval.h.def was not correct.

    Fixed how have_memmv.h is built.  On a number of systems, the have_memmv.c
    file failed to compile incorrectly, producing a potentially incorrect
    have_memmv.h file for such systems.

    Fixed how align32.h is built.  On a number of systems, the align32.c
    file failed to compile incorrectly, producing a potentially incorrect
    align32.h file for such systems.

    Fixed how have_newstr.h is built.  On a number of systems, the have_newstr.c
    failed to compile incorrectly, producing a potentially incorrect
    have_newstr.h file for such systems.

    Fixed how have_strdup.h is built.  On a number of systems, the have_strdup.c
    file failed to compile incorrectly, producing a potentially incorrect
    have_strdup.h file for such systems.

    Fixed how have_strlcat.h is built.  On a number of systems, the have_strlcat.c
    file failed to compile incorrectly, producing a potentially incorrect
    have_strlcat.h file for such systems.

    Fixed how have_strlcpy.h is built.  On a number of systems, the have_strlcpy.c
    file failed to compile incorrectly, producing a potentially incorrect
    have_strlcpy.h file for such systems.

    Fixed how have_uid_t.h is built.  On a number of systems, the have_uid_t.c
    file failed to compile incorrectly, producing a potentially incorrect
    have_uid_t.h file for such systems.

    Fixed how have_uid_t.h is built.  On a number of systems, the have_uid_t.c
    file failed to compile incorrectly, producing a potentially incorrect
    have_uid_t.h file for such systems.
2022-11-27 13:41:32 -08:00
Landon Curt Noll
3b3bfb3f74 Proposed changes for v2.14.1.1
Added a few remarks on calc version numbers to version.c.

Fixed how fposval.h is built.  On a number of systems, the fposval.c
file failed to compile incorrectly.  This caused problems for systems in
which fposval.h.def was not correct.

Fixed how have_memmv.h is built.  On a number of systems, the have_memmv.c
file failed to compile incorrectly, producing a potentially incorrect
have_memmv.h file for such systems.

Fixed how align32.h is built.  On a number of systems, the align32.c
file failed to compile incorrectly, producing a potentially incorrect
align32.h file for such systems.

Fixed how have_newstr.h is built.  On a number of systems, the have_newstr.c
failed to compile incorrectly, producing a potentially incorrect
have_newstr.h file for such systems.

Fixed how have_strdup.h is built.  On a number of systems, the have_strdup.c
file failed to compile incorrectly, producing a potentially incorrect
have_strdup.h file for such systems.

Fixed how have_strlcat.h is built.  On a number of systems, the have_strlcat.c
file failed to compile incorrectly, producing a potentially incorrect
have_strlcat.h file for such systems.

Fixed how have_strlcpy.h is built.  On a number of systems, the have_strlcpy.c
file failed to compile incorrectly, producing a potentially incorrect
have_strlcpy.h file for such systems.

Fixed how have_uid_t.h is built.  On a number of systems, the have_uid_t.c
file failed to compile incorrectly, producing a potentially incorrect
have_uid_t.h file for such systems.

Fixed how have_uid_t.h is built.  On a number of systems, the have_uid_t.c
file failed to compile incorrectly, producing a potentially incorrect
have_uid_t.h file for such systems.
2022-11-27 13:28:32 -08:00
Landon Curt Noll
3e4391e2af Fix another comment in comma.cal 2022-06-20 19:39:11 -07:00
Landon Curt Noll
cfc6a6669c Improve comments in comma.cal 2022-06-20 19:36:54 -07:00
Landon Curt Noll
fa457db3cd Fix more comments in cal/comma.cal 2022-06-20 19:30:45 -07:00
Landon Curt Noll
d08b958a15 Fix typo in comma.cal comment 2022-06-20 19:28:16 -07:00
Landon Curt Noll
5f28e5b851 Removed training newline from fprint_comma in comma.cal 2022-06-20 19:26:35 -07:00
Landon Curt Noll
8dc52a532a Fix comma.cal to avoid leading 0's and tilde's 2022-06-20 19:20:34 -07:00
Landon Curt Noll
6fc14730c0 Fix the forming of fraction part in comma.cal 2022-06-20 19:10:20 -07:00
Landon Curt Noll
b97093e58c Fix calc man page \-escape, add cal/comma.cal
Fixed a \-escape bug in calc(1) man page.

Added cal/comma.cal:

    Convert numbers into strings with 3-digit group and integer-fraction
    separators.

    If the value is an integer, the integer-fraction separator is not used.

    str_comma(x, [group, [decimal]])

	Convert x into a string.

	If group is given and is a string, group will be used as
	the 3-digit group separator, otherwise the default 3-digit
	group separator will be used.

	If decimal is given and is a string, group will be used as
	the integer-fraction separator, otherwise the default
	integer-fraction separator will be used.

	The decimal and group arguments are optional.

    set_default_group_separator(group)

	Change the default 3-digit group separator if group is a string,
	otherwise the default 3-digit group separator will not be
	changed.  Return the old 3-digit group separator.

    set_default_decimal_separator(decimal)

	Change the default 3-digit group separator if decimal is a
	string, otherwise the default integer-fraction separator
	will not be changed.  Return the old integer-fraction separator.

    print_comma(x, [group, [decimal]])

	Print the value produced by str_comma(x, [group, [decimal]])
	followed by a newline.

	If the str_comma() does not return a string, nothing is printed.

	The decimal and group arguments are optional.

	The value produced by str_comma() is returned.

    fprint_comma(fd, x, [group, [decimal]])

	Print the value produced by str_comma(x, [group, [decimal]]),
	without a trailing newline, on file fd.

	If the str_comma() does not return a string, nothing is printed.

	If fd is not an open file, nothing is printed.

	The decimal and group arguments are optional.

	The value produced by str_comma() is returned.
2022-06-20 18:25:12 -07:00
Landon Curt Noll
923c36e475 Remove excess whitespace under SECURITY.md 2022-04-08 00:24:42 -07:00
14 changed files with 678 additions and 28 deletions

97
CHANGES
View File

@@ -6,6 +6,103 @@ The following are the changes from calc version 2.14.1.0 to date:
Adjusted cal/test8900.cal to reflect this bug fix.
Added tests to cal/regress.cal to help verify bug fix is fixed.
Fixed a \-escape bug in calc(1) man page.
Added cal/comma.cal:
Convert numbers into strings with 3-digit group and integer-fraction
separators.
If the value is an integer, the integer-fraction separator is not used.
str_comma(x, [group, [decimal]])
Convert x into a string.
If group is given and is a string, group will be used as
the 3-digit group separator, otherwise the default 3-digit
group separator will be used.
If decimal is given and is a string, group will be used as
the integer-fraction separator, otherwise the default
integer-fraction separator will be used.
The decimal and group arguments are optional.
set_default_group_separator(group)
Change the default 3-digit group separator if group is a string,
otherwise the default 3-digit group separator will not be
changed. Return the old 3-digit group separator.
set_default_decimal_separator(decimal)
Change the default 3-digit group separator if decimal is a
string, otherwise the default integer-fraction separator
will not be changed. Return the old integer-fraction separator.
print_comma(x, [group, [decimal]])
Print the value produced by str_comma(x, [group, [decimal]])
followed by a newline.
If the str_comma() does not return a string, nothing is printed.
The decimal and group arguments are optional.
The value produced by str_comma() is returned.
fprint_comma(fd, x, [group, [decimal]])
Print the value produced by str_comma(x, [group, [decimal]]),
without a trailing newline, on file fd.
If the str_comma() does not return a string, nothing is printed.
If fd is not an open file, nothing is printed.
The decimal and group arguments are optional.
The value produced by str_comma() is returned.
Added a few remarks on calc version numbers to version.c.
Fixed how fposval.h is built. On a number of systems, the fposval.c
file failed to compile incorrectly. This caused problems for systems in
which fposval.h.def was not correct.
Fixed how have_memmv.h is built. On a number of systems, the have_memmv.c
file failed to compile incorrectly, producing a potentially incorrect
have_memmv.h file for such systems.
Fixed how align32.h is built. On a number of systems, the align32.c
file failed to compile incorrectly, producing a potentially incorrect
align32.h file for such systems.
Fixed how have_newstr.h is built. On a number of systems, the have_newstr.c
failed to compile incorrectly, producing a potentially incorrect
have_newstr.h file for such systems.
Fixed how have_strdup.h is built. On a number of systems, the have_strdup.c
file failed to compile incorrectly, producing a potentially incorrect
have_strdup.h file for such systems.
Fixed how have_strlcat.h is built. On a number of systems, the have_strlcat.c
file failed to compile incorrectly, producing a potentially incorrect
have_strlcat.h file for such systems.
Fixed how have_strlcpy.h is built. On a number of systems, the have_strlcpy.c
file failed to compile incorrectly, producing a potentially incorrect
have_strlcpy.h file for such systems.
Fixed how have_uid_t.h is built. On a number of systems, the have_uid_t.c
file failed to compile incorrectly, producing a potentially incorrect
have_uid_t.h file for such systems.
Fixed how have_uid_t.h is built. On a number of systems, the have_uid_t.c
file failed to compile incorrectly, producing a potentially incorrect
have_uid_t.h file for such systems.
The following are the changes from calc version 2.14.0.15 to 2.14.0.15:

View File

@@ -1309,7 +1309,7 @@ EXT=
# The default calc versions
#
VERSION= 2.14.1.0
VERSION= 2.14.1.1
# Names of shared libraries with versions
#
@@ -3264,7 +3264,8 @@ have_fpos_pos.h: have_fpos_pos.c have_fpos.h have_posscl.h \
fposval.h: fposval.c have_fpos.h have_fpos_pos.h have_offscl.h have_posscl.h \
endian_calc.h banned.h have_ban_pragma.h fposval.h.def alloc.h \
have_newstr.h have_memmv.h ${MAKE_FILE} ${LOC_MKF}
have_newstr.h have_memmv.h have_string.h have_const.h have_string.h \
have_unused.h ${MAKE_FILE} ${LOC_MKF}
${Q} ${RM} -f fposval_tmp $@
${H} echo 'forming $@'
${Q} echo '/*' > $@
@@ -3431,7 +3432,7 @@ have_posscl.h: have_posscl.c have_fpos.h have_unistd.h \
fi
align32.h: align32.c longbits.h have_unistd.h \
banned.h have_ban_pragma.h ${MAKE_FILE} ${LOC_MKF}
banned.h have_ban_pragma.h have_unused.h ${MAKE_FILE} ${LOC_MKF}
${Q} ${RM} -f align32 align32_tmp $@
${H} echo 'forming $@'
${Q} echo '/*' > $@
@@ -3609,7 +3610,7 @@ have_arc4random.h: have_arc4random.c have_stdlib.h \
${TRUE}; \
fi
have_newstr.h: have_newstr.c banned.h have_ban_pragma.h ${MAKE_FILE} ${LOC_MKF}
have_newstr.h: have_newstr.c banned.h have_ban_pragma.h have_string.h ${MAKE_FILE} ${LOC_MKF}
${Q} ${RM} -f newstr_tmp $@
${H} echo 'forming $@'
${Q} echo '/*' > $@
@@ -3649,7 +3650,7 @@ have_newstr.h: have_newstr.c banned.h have_ban_pragma.h ${MAKE_FILE} ${LOC_MKF}
${TRUE}; \
fi
have_memmv.h: have_memmv.c banned.h have_ban_pragma.h ${MAKE_FILE} ${LOC_MKF}
have_memmv.h: have_memmv.c banned.h have_ban_pragma.h have_string.h ${MAKE_FILE} ${LOC_MKF}
${Q} ${RM} -f have_memmv have_memmv.o memmv_tmp $@
${H} echo 'forming $@'
${Q} echo '/*' > $@
@@ -3968,7 +3969,7 @@ have_rusage.h: have_rusage.c banned.h have_ban_pragma.h ${MAKE_FILE} ${LOC_MKF}
${TRUE}; \
fi
have_strdup.h: have_strdup.c banned.h have_ban_pragma.h ${MAKE_FILE} ${LOC_MKF}
have_strdup.h: have_strdup.c banned.h have_ban_pragma.h have_string.h ${MAKE_FILE} ${LOC_MKF}
${Q} ${RM} -f strdup_tmp $@
${H} echo 'forming $@'
${Q} echo '/*' > $@
@@ -4206,7 +4207,7 @@ have_ban_pragma.h: have_ban_pragma.c banned.h ${MAKE_FILE} ${LOC_MKF}
${TRUE}; \
fi
have_strlcpy.h: have_strlcpy.c banned.h have_ban_pragma.h \
have_strlcpy.h: have_strlcpy.c banned.h have_ban_pragma.h have_string.h \
${MAKE_FILE} ${LOC_MKF}
${Q} ${RM} -f unused_tmp $@
${H} echo 'forming $@'
@@ -4248,7 +4249,7 @@ have_strlcpy.h: have_strlcpy.c banned.h have_ban_pragma.h \
${TRUE}; \
fi
have_strlcat.h: have_strlcat.c banned.h have_ban_pragma.h \
have_strlcat.h: have_strlcat.c banned.h have_ban_pragma.h have_string.h \
${MAKE_FILE} ${LOC_MKF}
${Q} ${RM} -f unused_tmp $@
${H} echo 'forming $@'
@@ -5802,7 +5803,9 @@ addop.o: zmath.h
align32.o: align32.c
align32.o: banned.h
align32.o: have_ban_pragma.h
align32.o: have_stdlib.h
align32.o: have_unistd.h
align32.o: have_unused.h
align32.o: longbits.h
assocfunc.o: alloc.h
assocfunc.o: assocfunc.c
@@ -6153,9 +6156,11 @@ file.o: value.h
file.o: zmath.h
fposval.o: alloc.h
fposval.o: banned.h
fposval.o: decl.h
fposval.o: endian_calc.h
fposval.o: fposval.c
fposval.o: have_ban_pragma.h
fposval.o: have_const.h
fposval.o: have_fpos.h
fposval.o: have_fpos_pos.h
fposval.o: have_memmv.h
@@ -6163,6 +6168,7 @@ fposval.o: have_newstr.h
fposval.o: have_offscl.h
fposval.o: have_posscl.h
fposval.o: have_string.h
fposval.o: have_unused.h
func.o: alloc.h
func.o: attribute.h
func.o: banned.h

View File

@@ -1151,7 +1151,7 @@ EXT=
# The default calc versions
#
VERSION= 2.14.1.0
VERSION= 2.14.1.1
# Names of shared libraries with versions
#
@@ -2578,7 +2578,8 @@ have_fpos_pos.h: have_fpos_pos.c have_fpos.h have_posscl.h \
fposval.h: fposval.c have_fpos.h have_fpos_pos.h have_offscl.h have_posscl.h \
endian_calc.h banned.h have_ban_pragma.h fposval.h.def alloc.h \
have_newstr.h have_memmv.h ${MAKE_FILE} ${LOC_MKF}
have_newstr.h have_memmv.h have_string.h have_const.h have_string.h \
have_unused.h ${MAKE_FILE} ${LOC_MKF}
${Q} ${RM} -f fposval_tmp $@
${H} echo 'forming $@'
${Q} echo '/*' > $@
@@ -2745,7 +2746,7 @@ have_posscl.h: have_posscl.c have_fpos.h have_unistd.h \
fi
align32.h: align32.c longbits.h have_unistd.h \
banned.h have_ban_pragma.h ${MAKE_FILE} ${LOC_MKF}
banned.h have_ban_pragma.h have_unused.h ${MAKE_FILE} ${LOC_MKF}
${Q} ${RM} -f align32 align32_tmp $@
${H} echo 'forming $@'
${Q} echo '/*' > $@
@@ -2923,7 +2924,7 @@ have_arc4random.h: have_arc4random.c have_stdlib.h \
${TRUE}; \
fi
have_newstr.h: have_newstr.c banned.h have_ban_pragma.h ${MAKE_FILE} ${LOC_MKF}
have_newstr.h: have_newstr.c banned.h have_ban_pragma.h have_string.h ${MAKE_FILE} ${LOC_MKF}
${Q} ${RM} -f newstr_tmp $@
${H} echo 'forming $@'
${Q} echo '/*' > $@
@@ -2963,7 +2964,7 @@ have_newstr.h: have_newstr.c banned.h have_ban_pragma.h ${MAKE_FILE} ${LOC_MKF}
${TRUE}; \
fi
have_memmv.h: have_memmv.c banned.h have_ban_pragma.h ${MAKE_FILE} ${LOC_MKF}
have_memmv.h: have_memmv.c banned.h have_ban_pragma.h have_string.h ${MAKE_FILE} ${LOC_MKF}
${Q} ${RM} -f have_memmv have_memmv.o memmv_tmp $@
${H} echo 'forming $@'
${Q} echo '/*' > $@
@@ -3282,7 +3283,7 @@ have_rusage.h: have_rusage.c banned.h have_ban_pragma.h ${MAKE_FILE} ${LOC_MKF}
${TRUE}; \
fi
have_strdup.h: have_strdup.c banned.h have_ban_pragma.h ${MAKE_FILE} ${LOC_MKF}
have_strdup.h: have_strdup.c banned.h have_ban_pragma.h have_string.h ${MAKE_FILE} ${LOC_MKF}
${Q} ${RM} -f strdup_tmp $@
${H} echo 'forming $@'
${Q} echo '/*' > $@
@@ -3520,7 +3521,7 @@ have_ban_pragma.h: have_ban_pragma.c banned.h ${MAKE_FILE} ${LOC_MKF}
${TRUE}; \
fi
have_strlcpy.h: have_strlcpy.c banned.h have_ban_pragma.h \
have_strlcpy.h: have_strlcpy.c banned.h have_ban_pragma.h have_string.h \
${MAKE_FILE} ${LOC_MKF}
${Q} ${RM} -f unused_tmp $@
${H} echo 'forming $@'
@@ -3562,7 +3563,7 @@ have_strlcpy.h: have_strlcpy.c banned.h have_ban_pragma.h \
${TRUE}; \
fi
have_strlcat.h: have_strlcat.c banned.h have_ban_pragma.h \
have_strlcat.h: have_strlcat.c banned.h have_ban_pragma.h have_string.h \
${MAKE_FILE} ${LOC_MKF}
${Q} ${RM} -f unused_tmp $@
${H} echo 'forming $@'
@@ -5070,7 +5071,9 @@ addop.o: zmath.h
align32.o: align32.c
align32.o: banned.h
align32.o: have_ban_pragma.h
align32.o: have_stdlib.h
align32.o: have_unistd.h
align32.o: have_unused.h
align32.o: longbits.h
assocfunc.o: alloc.h
assocfunc.o: assocfunc.c
@@ -5421,9 +5424,11 @@ file.o: value.h
file.o: zmath.h
fposval.o: alloc.h
fposval.o: banned.h
fposval.o: decl.h
fposval.o: endian_calc.h
fposval.o: fposval.c
fposval.o: have_ban_pragma.h
fposval.o: have_const.h
fposval.o: have_fpos.h
fposval.o: have_fpos_pos.h
fposval.o: have_memmv.h
@@ -5431,6 +5436,7 @@ fposval.o: have_newstr.h
fposval.o: have_offscl.h
fposval.o: have_posscl.h
fposval.o: have_string.h
fposval.o: have_unused.h
func.o: alloc.h
func.o: attribute.h
func.o: banned.h

View File

@@ -15,5 +15,5 @@ FYI: please review the BUGS file, or enter the calc command:
Please create a calc GitHub repo issue:
https://github.com/lcn2/calc/issues
Click on ((New issue)) and follow the issue template.

View File

@@ -27,6 +27,11 @@
#include <stdio.h>
#include <signal.h>
#include "have_stdlib.h"
#if defined(HAVE_STDLIB_H)
#include <stdlib.h>
#endif
#include "longbits.h"
#include "have_unistd.h"
@@ -34,11 +39,13 @@
#include <unistd.h>
#endif
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
static void buserr(void); /* catch alignment errors */
static void buserr(int arg); /* catch alignment errors */
int
@@ -46,7 +53,7 @@ main(void)
{
char byte[2*sizeof(USB32)]; /* mis-alignment buffer */
USB32 *p; /* mis-alignment pointer */
int i;
unsigned long i;
#if defined(MUST_ALIGN32)
/* force alignment */
@@ -82,7 +89,7 @@ main(void)
*/
/*ARGSUSED*/
static void
buserr(int arg)
buserr(int UNUSED(arg))
{
/* alignment is required */
printf("#define MUST_ALIGN32\t%c* must align 32 bit values *%c\n",

View File

@@ -267,9 +267,9 @@ TRUE= true
#
CALC_FILES= README alg_config.cal beer.cal bernoulli.cal \
bernpoly.cal bigprime.cal bindings brentsolve.cal chi.cal chrem.cal \
constants.cal deg.cal dms.cal dotest.cal ellip.cal factorial.cal \
factorial2.cal gvec.cal hello.cal hms.cal infinities.cal intfile.cal \
intnum.cal lambertw.cal linear.cal lnseries.cal lucas.cal \
comma.cal constants.cal deg.cal dms.cal dotest.cal ellip.cal \
factorial.cal factorial2.cal gvec.cal hello.cal hms.cal infinities.cal \
intfile.cal intnum.cal lambertw.cal linear.cal lnseries.cal lucas.cal \
lucas_chk.cal mersenne.cal mfactor.cal mod.cal natnumset.cal \
palindrome.cal pell.cal pi.cal pix.cal pollard.cal poly.cal prompt.cal \
psqrt.cal qtime.cal quat.cal randbitrun.cal randmprime.cal \

View File

@@ -263,6 +263,64 @@ chrem.cal
Chinese remainder theorem/problem solver.
comma.cal
Convert numbers into strings with 3-digit group and integer-fraction
separators.
If the value is an integer, the integer-fraction separator is not used.
str_comma(x, [group, [decimal]])
Convert x into a string.
If group is given and is a string, group will be used as
the 3-digit group separator, otherwise the default 3-digit
group separator will be used.
If decimal is given and is a string, group will be used as
the integer-fraction separator, otherwise the default
integer-fraction separator will be used.
The decimal and group arguments are optional.
set_default_group_separator(group)
Change the default 3-digit group separator if group is a string,
otherwise the default 3-digit group separator will not be
changed. Return the old 3-digit group separator.
set_default_decimal_separator(decimal)
Change the default 3-digit group separator if decimal is a
string, otherwise the default integer-fraction separator
will not be changed. Return the old integer-fraction separator.
print_comma(x, [group, [decimal]])
Print the value produced by str_comma(x, [group, [decimal]])
followed by a newline.
If the str_comma() does not return a string, nothing is printed.
The decimal and group arguments are optional.
The value produced by str_comma() is returned.
fprint_comma(fd, x, [group, [decimal]])
Print the value produced by str_comma(x, [group, [decimal]]),
without a trailing newline, on file fd.
If the str_comma() does not return a string, nothing is printed.
If fd is not an open file, nothing is printed.
The decimal and group arguments are optional.
The value produced by str_comma() is returned.
deg.cal
deg(deg, min, sec)

437
cal/comma.cal Normal file
View File

@@ -0,0 +1,437 @@
/*
* comma - convert numbers into strings with 3-digit group and integer-fraction separators
*
* Convert numbers into strings with 3-digit group and integer-fraction separators.
*
* If the value is an integer, the integer-fraction separator is not used.
*
* str_comma(x, [group, [decimal]])
*
* Convert x into a string.
*
* If group is given and is a string, group will be used as
* the 3-digit group separator, otherwise the default 3-digit
* group separator will be used.
*
* If decimal is given and is a string, group will be used as
* the integer-fraction separator, otherwise the default
* integer-fraction separator will be used.
*
* The decimal and group arguments are optional.
*
* set_default_group_separator(group)
*
* Change the default 3-digit group separator if group is a string,
* otherwise the default 3-digit group separator will not be
* changed. Return the old 3-digit group separator.
*
* set_default_decimal_separator(decimal)
*
* Change the default 3-digit group separator if decimal is a
* string, otherwise the default integer-fraction separator
* will not be changed. Return the old integer-fraction separator.
*
* print_comma(x, [group, [decimal]])
*
* Print the value produced by str_comma(x, [group, [decimal]])
* followed by a newline.
*
* If the str_comma() does not return a string, nothing is printed.
*
* The decimal and group arguments are optional.
*
* The value produced by str_comma() is returned.
*
* fprint_comma(fd, x, [group, [decimal]])
*
* Print the value produced by str_comma(x, [group, [decimal]]),
* without a trailing newline, on file fd.
*
* If the str_comma() does not return a string, nothing is printed.
*
* If fd is not an open file, nothing is printed.
*
* The decimal and group arguments are optional.
*
* The value produced by str_comma() is returned.
*
* Copyright (C) 2022 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
* as published by the Free Software Foundation.
*
* Calc is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* A copy of version 2.1 of the GNU Lesser General Public License is
* distributed with calc under the filename COPYING-LGPL. You should have
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 2022/06/20 15:51:49
* File existed as early as: 2022
*
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
static default_group_separator = ","; /* default 3-digit group separator */
static default_decimal_separator = "."; /* default integer-fraction separator */
/*
* str_comma - convert number into base 10 string with 3-digit groups and integer-fraction separator
*
*
* This function converts a real number into a base 10 string, where
* groups of 3 digits are separated by a 3-digit group separator and
* a integer-fraction separator is printed between integer and decimal fraction.
*
* For example:
*
* string = str_comma(x);
* string = str_comma(x), " ", ".");
* string = str_comma(x), ".", ",");
*
* Internally the function calls:
*
* strprintf("%f", x);
*
* and thus the number of decimal fraction digits is subject to
* the display() or config("display") value. See:
*
* man display
*
* for details.
*
* given:
*
* x number to convert
*
* optional args:
*
* group use this 3-digit group separator
* decimal use this integer-fraction separator
*
* returns:
*
* string containing the base 10 digits with group and decimal separators, OR
* null() if x is not a number, OR
* null() if group is neither null() (not given) nor a string, OR
* null() if group is null() (not given) AND default_group_separator is not a string, OR
* null() if decimal is neither null() (not given) nor a string, OR
* null() if decimal is null() (not given) AND default_decimal_separator is not a string.
*/
define str_comma(x, group, decimal)
{
local group_separator; /* 3-digit group separator */
local decimal_separator; /* separator between decimal integer and decimal fraction */
local sign_str; /* leading - if x < 0 or empty if x >= 0 */
local integer; /* integer part of absolute value of x */
local int_str; /* integer as a string */
local int_len; /* number of digits in int_str */
local first_group_len; /* length of 1st group before the 1st 3-digit group separator */
local fraction; /* factional part of absolute value of x */
local frac_str; /* fraction as a string */
local frac_len; /* number of digits in frac_str including leading 0. */
local ret; /* string to return */
local config_leadzero; /* config("leadzero") to restore */
local config_tilde; /* config("tilde") to restore */
local i;
/*
* parse args - return null if args are bogus
*
* Return null() if args or conditions are bogus.
*/
if (!isreal(x)) {
return null();
}
group_separator = isnull(group) ? default_group_separator : group;
decimal_separator = isnull(decimal) ? default_decimal_separator : decimal;
if (!isstr(group_separator)) {
return null();
}
if (!isstr(decimal_separator)) {
return null();
}
/*
* split number
*/
if (x < 0) {
sign_str = "-";
integer = int(-x);
fraction = frac(-x);
} else {
sign_str = "";
integer = int(x);
fraction = frac(x);
}
ret = sign_str;
/*
* convert digits
*
* Avoid printing ~ and leading zeros for factional part.
*/
int_str = strprintf("%d", integer);
config_leadzero = config("leadzero", 0);
config_tilde = config("tilde", 0);
frac_str = strprintf("%d", fraction);
config("leadzero", config_leadzero),;
config("tilde", config_tilde),;
/*
* determine number of digits in the integer part
*/
int_len = strlen(int_str);
frac_len = strlen(frac_str);
/*
* form integer part with group separators as needed
*/
/*
* case: integer is 3 or fewer digits
*/
if (integer < 1000) {
ret += int_str;
/*
* case: integer is 4 or more digits
*/
} else {
/*
* form a decimal string using group separators
*/
/*
* form the initial leading digits before 1st group separator
*/
first_group_len = int_len % 3;
if (first_group_len == 0) {
first_group_len = 3;
}
ret += substr(int_str, 1, first_group_len);
/*
* until end of digits, print group separator followed by 3 more digits
*/
for (i = first_group_len+1; i < int_len; i += 3) {
ret += group_separator + substr(int_str, i, 3);
}
}
/*
* form fractional part using decimal separator as needed
*/
/*
* case: x is an integer
*/
if (fraction == 0) {
/* no fraction, nothing more to do */
/*
* case: x is not an integer
*/
} else {
/*
* add integer-fraction separator
*/
ret += decimal_separator;
/*
* add remaining digits
*
* Skip over the leading 0. in frac_str
*/
ret += substr(frac_str, 2, frac_len-1);
}
/*
* All Done!!! -- Jessica Noll, Age 2
*/
return ret;
}
/*
* set_default_group_separator - change the default 3-digit group separator
*
* If group is not a string, then the default 3-digit group separator
* is not changed. Thus, this will only return the default 3-digit group separator:
*
* set_default_group_separator(null());
*
* given:
*
* group 3-digit group separator
*
* returns:
*
* previous 3-digit group separator value
*/
define set_default_group_separator(group)
{
local old_default_group_separator; /* previous default 3-digit group separator to return */
/*
* save current 3-digit group separator
*/
old_default_group_separator = default_group_separator;
/*
* change 3-digit group separator if group is a string
*/
if (isstr(group)) {
default_group_separator = group;
}
return old_default_group_separator;
}
/*
* set_default_decimal_separator - change the default integer-fraction separator
*
* If decimal is not a string, then the default integer-fraction separator
* is not changed. Thus, this will only return the integer-fraction separator:
*
* set_default_decimal_separator(null());
*
* given:
*
* decimal separator between decimal integer and decimal fraction (def: ".")
*
* returns:
*
* previous integer-fraction separator value
*/
define set_default_decimal_separator(decimal)
{
local old_default_decimal_separator; /* previous default integer-fraction separator */
/*
* save current integer-fraction separator
*/
old_default_decimal_separator = default_decimal_separator;
/*
* change 3-digit decimal integer-fraction if decimal is a string
*/
if (isstr(decimal)) {
default_decimal_separator = decimal;
}
return old_default_decimal_separator;
}
/*
* print_comma - print base 10 string with 3-digit group separators & integer-fraction separator + newline
*
* This function prints the result of str_comma(x, group, decimal) followed by a newline.
* For example:
*
* print_comma(x);
* print_comma(x), " ", ".");
* print_comma(x), ".", ",");
*
* If str_comma() does not return a string, this function prints nothing.
*
* NOTE: To print without a newline, use fprint_comma(fd, x, group, decimal).
*
* given:
* x number to convert
*
* optional args:
*
* group use this 3-digit group separator
* decimal use this integer-fraction separator
*
* returns:
*
* string containing the base 10 digits with group and decimal separators, OR
* null() if x is not a number, OR
* null() if group is neither null() (not given) nor a string, OR
* null() if group is null() (not given) AND default_group_separator is not a string, OR
* null() if decimal is neither null() (not given) nor a string, OR
* null() if decimal is null() (not given) AND default_decimal_separator is not a string.
*/
define print_comma(x, group, decimal)
{
local ret; /* base 10 string with 3-digit group and integer-fraction separators */
/*
* convert to string
*/
ret = str_comma(x, group, decimal);
/*
* print converted string
*/
if (isstr(ret)) {
printf("%s\n", ret);
}
return ret;
}
/*
* fprint_comma - print base 10 string with 3-digit group separators & integer-fraction separator w/o newline
*
* This function prints the result of str_comma(x, group, decimal) on an open file, without a trailing newline.
* For example:
*
* fprint_comma(files(1), x);
* fprint_comma(fd, x), " ", ".");
* fprint_comma(files(2), x), ".", ",");
*
* If str_comma() does not return a string, this function prints nothing.
*
* This function flushes output to the open file before returning.
*
* NOTE: To print with a newline, use print_comma(x, group, decimal).
*
* given:
* fd open file
* x number to convert
*
* optional args:
*
* group use this 3-digit group separator
* decimal use this integer-fraction separator
*
* returns:
*
* string containing the base 10 digits with group and integer-fraction separators, OR
* null() if x is not a number, OR
* null() if group is neither null() (not given) nor a string, OR
* null() if group is null() (not given) AND default_group_separator is not a string, OR
* null() if decimal is neither null() (not given) nor a string, OR
* null() if decimal is null() (not given) AND default_decimal_separator is not a string.
*/
define fprint_comma(fd, x, group, decimal)
{
local ret; /* base 10 string with 3-digit group and integer-fraction separators */
/*
* convert to string
*/
ret = str_comma(x, group, decimal);
/*
* print converted string
*/
if (isstr(ret) && isfile(fd)) {
fprintf(fd, "%s", ret);
fflush(fd);
}
return ret;
}

View File

@@ -596,7 +596,7 @@ may have to be replaced by:
.sp 1
.in +5n
.nf
print 27! ^2 or print 27\!^2
print 27! ^2 or print 27\\!^2
.fi
.in -5n

View File

@@ -474,7 +474,7 @@ EXT=
# The default calc versions
#
VERSION= 2.14.1.0
VERSION= 2.14.1.1
# Names of shared libraries with versions
#

View File

@@ -445,7 +445,7 @@ EXT=
# The default calc versions
#
VERSION= 2.14.1.0
VERSION= 2.14.1.1
# Names of shared libraries with versions
#

View File

@@ -59,12 +59,19 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "decl.h"
#include "have_fpos.h"
#include "endian_calc.h"
#include "have_offscl.h"
#include "have_posscl.h"
#include "have_fpos_pos.h"
#include "alloc.h"
#include "have_unused.h"
#include "have_memmv.h"
#include "banned.h" /* include after system header <> includes */
@@ -73,7 +80,7 @@
char *program; /* our name */
int
main(int argc, char **argv)
main(int UNUSED(argc), char **argv)
{
int stsizelen; /* bit length of st_size in buf */
int fileposlen; /* bit length of FILEPOS */

View File

@@ -65,6 +65,8 @@ main(void)
extern uid_t geteuid();
curds = geteuid();
/* force curds to be used, but do not print much info about our UID */
printf("/* geteuid() mod 2 == %ld */\n", ((long)curds) & 0x1);
printf("#define HAVE_UID_T /* yes */\n");

View File

@@ -51,10 +51,40 @@ static char *program;
#include "banned.h" /* include after system header <> includes */
/*
* MAJOR_VER
*
* The MAJOR_VER remains at 2. That are concepts for version 3 calc,
* but that is a long way off. One of the main reasons why MAJOR_VER
* might incremented is if fundamental calc data objects (such as when ZVALUE
* or NUMBER or COMPLEX need to change) that would cause an incompatibility
* with existing hardware accelerators that are using fundamental calc data objects.
*
* MINOR_VER
*
* The MINOR_VER changes when there are incompatible changes to the calc library
* or calc custom library. The MINOR_VER might change if we need to make a major
* change to the math engine. For example, when the way 0^x was evaluated, we
* changed MINOR_VER from 13 to 14.
*
* MAJOR_PATCH
*
* The MAJOR_PATCH changes when there is an update to the calc library
* or calc custom library. For example, the MAJOR_PATCH might increment when there
* are new builtin functions available, or when there is a change to how existing
* builtin functions process arguments.
*
* MINOR_PATCH
*
* The MINOR_PATCH changes whenever there is any change in the calc release.
* For example, when the documentation changes, the MINOR_PATCH will increment.
* Moreover, when we are working towards a new production release,
* bug fix and improvement updates will cause MINOR_PATCH to increment.
*/
#define MAJOR_VER 2 /* major library version */
#define MINOR_VER 14 /* minor library version */
#define MAJOR_PATCH 1 /* major software version level */
#define MINOR_PATCH 0 /* minor software version level */
#define MINOR_PATCH 1 /* minor software version level */
/*