Rename array_size to array_length.

* src/include/lib.h (array_size): Rename to...
  (array_length): ...this.

* src/preproc/eqn/box.cpp (set_param, reset_param, get_param)
  (init_param_table, free_param_table): Migrate call sites.

Thanks to Alex Colomar for the discussion.

See <https://lists.gnu.org/archive/html/groff/2023-08/msg00140.html>.

Acked-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
G. Branden Robinson 2023-08-28 15:06:20 -05:00
parent e5f6d91b6d
commit e0cb0910cb
4 changed files with 23 additions and 7 deletions

View File

@ -1,3 +1,13 @@
2023-08-28 G. Branden Robinson <g.branden.robinson@gmail.com>
* src/include/lib.h (array_size): Rename to...
(array_length): ...this.
* src/preproc/eqn/box.cpp (set_param, reset_param, get_param)
(init_param_table, free_param_table): Migrate call sites.
Thanks to Alex Colomar for the discussion.
2023-08-28 G. Branden Robinson <g.branden.robinson@gmail.com>
* Makefile.am (EXTRA_DIST): Ship ancient groff ChangeLog files

View File

@ -22,6 +22,12 @@ Standard Template Library is little used. A modest effort is underway
to update the code to more idiomatic C++98. Where a C++11 feature
promises to be advantageous, it may be annotated in a code comment.
Portability notes:
* `std::size` is not available in C++98. Use the `array_length`
template function in src/include/lib.h instead of `sizeof` and
dividing.
Automake
--------

View File

@ -155,7 +155,7 @@ static const double PI = 3.14159265358979323846;
#ifdef __cplusplus
template <typename T, size_t N>
// constexpr // C++11
size_t array_size(T(&)[N]) {
size_t array_length(T(&)[N]) {
return N;
}
#endif

View File

@ -135,7 +135,7 @@ struct param *param_table = 0 /* nullptr */;
void set_param(const char *name, int value)
{
for (size_t i = 0; i <= array_size(default_param_table); i++)
for (size_t i = 0; i <= array_length(default_param_table); i++)
if (strcmp(param_table[i].name, name) == 0) {
*(param_table[i].ptr) = value;
return;
@ -145,7 +145,7 @@ void set_param(const char *name, int value)
void reset_param(const char *name)
{
for (size_t i = 0; i < array_size(default_param_table); i++)
for (size_t i = 0; i < array_length(default_param_table); i++)
if (strcmp(param_table[i].name, name) == 0) {
*param_table[i].ptr = *(default_param_table[i].ptr);
return;
@ -156,7 +156,7 @@ void reset_param(const char *name)
int get_param(const char *name)
{
for (size_t i = 0; i < array_size(default_param_table); i++)
for (size_t i = 0; i < array_length(default_param_table); i++)
if (strcmp(param_table[i].name, name) == 0)
return *(param_table[i].ptr);
assert(0 == "attempted to access parameter not in table");
@ -165,8 +165,8 @@ int get_param(const char *name)
void init_param_table()
{
param_table = new param[array_size(default_param_table)];
for (size_t i = 0; i < array_size(default_param_table); i++) {
param_table = new param[array_length(default_param_table)];
for (size_t i = 0; i < array_length(default_param_table); i++) {
param_table[i].name = default_param_table[i].name;
param_table[i].ptr = new int(*(default_param_table[i].ptr));
}
@ -175,7 +175,7 @@ void init_param_table()
void free_param_table()
{
if (param_table != 0 /* nullptr */) {
for (size_t i = 0; i < array_size(default_param_table); i++)
for (size_t i = 0; i < array_length(default_param_table); i++)
delete param_table[i].ptr;
delete[] param_table;
param_table = 0 /* nullptr */;