|
| 1 | +/** @file features.cc |
| 2 | + * |
| 3 | + * Utility code for printing available features. |
| 4 | + */ |
| 5 | +/* #[ License : */ |
| 6 | +/* |
| 7 | + * Copyright (C) 1984-2026 J.A.M. Vermaseren |
| 8 | + * When using this file you are requested to refer to the publication |
| 9 | + * J.A.M.Vermaseren "New features of FORM" math-ph/0010025 |
| 10 | + * This is considered a matter of courtesy as the development was paid |
| 11 | + * for by FOM the Dutch physics granting agency and we would like to |
| 12 | + * be able to track its scientific use to convince FOM of its value |
| 13 | + * for the community. |
| 14 | + * |
| 15 | + * This file is part of FORM. |
| 16 | + * |
| 17 | + * FORM is free software: you can redistribute it and/or modify it under the |
| 18 | + * terms of the GNU General Public License as published by the Free Software |
| 19 | + * Foundation, either version 3 of the License, or (at your option) any later |
| 20 | + * version. |
| 21 | + * |
| 22 | + * FORM is distributed in the hope that it will be useful, but WITHOUT ANY |
| 23 | + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 24 | + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 25 | + * details. |
| 26 | + * |
| 27 | + * You should have received a copy of the GNU General Public License along |
| 28 | + * with FORM. If not, see <http://www.gnu.org/licenses/>. |
| 29 | + */ |
| 30 | +/* #] License : */ |
| 31 | +// #[ Includes : |
| 32 | + |
| 33 | +extern "C" { |
| 34 | +#include "form3.h" |
| 35 | +} |
| 36 | + |
| 37 | +#include <algorithm> |
| 38 | +#include <string> |
| 39 | +#include <vector> |
| 40 | + |
| 41 | +#ifdef WITHFLINT |
| 42 | +#include <flint/flint.h> |
| 43 | +#endif |
| 44 | + |
| 45 | +#ifdef WITHGMP |
| 46 | +#include <gmp.h> |
| 47 | +#endif |
| 48 | + |
| 49 | +#ifdef WITHMPFR |
| 50 | +#include <mpfr.h> |
| 51 | +#endif |
| 52 | + |
| 53 | +#ifdef WITHZLIB |
| 54 | +#include <zlib.h> |
| 55 | +#endif |
| 56 | + |
| 57 | +#ifdef WITHZSTD |
| 58 | +#include <zstd.h> |
| 59 | +#endif |
| 60 | + |
| 61 | +// #] Includes : |
| 62 | +// #[ PrintFeatureList : |
| 63 | + |
| 64 | +/** |
| 65 | + * Prints a list of strings in multiple columns to fit within the line length. |
| 66 | + * |
| 67 | + * @param lines List of strings to print. |
| 68 | + */ |
| 69 | +static void PrintMulticolumn(const std::vector<std::string>& lines) |
| 70 | +{ |
| 71 | + const std::size_t n_lines = lines.size(); |
| 72 | + |
| 73 | + if ( n_lines == 0 ) return; |
| 74 | + |
| 75 | + const std::size_t line_len = AC.LineLength > 0 ? AC.LineLength : 79; |
| 76 | + constexpr std::size_t max_cols = 6; |
| 77 | + constexpr std::size_t col_spacing = 2; |
| 78 | + |
| 79 | + std::vector<std::size_t> col_lens(max_cols); |
| 80 | + |
| 81 | + for ( std::size_t n_cols = max_cols; n_cols >= 2; n_cols-- ) { |
| 82 | + const std::size_t n_rows = (n_lines - 1) / n_cols + 1; |
| 83 | + |
| 84 | + // Check whether `n_cols` columns fit within the line length. |
| 85 | + // Columns are filled top-to-bottom, then left-to-right. |
| 86 | + |
| 87 | + std::fill(col_lens.begin(),col_lens.begin()+n_cols,0); |
| 88 | + |
| 89 | + std::size_t total_len = 0; |
| 90 | + for ( std::size_t j = 0; j < n_cols; j++ ) { |
| 91 | + for ( std::size_t i = 0; i < n_rows; i++ ) { |
| 92 | + const std::size_t k = i + j * n_rows; |
| 93 | + if ( k >= n_lines ) break; |
| 94 | + col_lens[j] = std::max(col_lens[j],lines[k].size()); |
| 95 | + } |
| 96 | + total_len += col_lens[j]; |
| 97 | + } |
| 98 | + total_len += (n_cols - 1) * col_spacing; |
| 99 | + |
| 100 | + if ( total_len > line_len ) continue; |
| 101 | + |
| 102 | + // Output using `n_cols` columns. |
| 103 | + |
| 104 | + std::string line; |
| 105 | + line.reserve(line_len); |
| 106 | + for ( std::size_t i = 0; i < n_rows; i++ ) { |
| 107 | + line.clear(); |
| 108 | + for ( std::size_t j = 0; j < n_cols; j++ ) { |
| 109 | + const std::size_t k = i + j * n_rows; |
| 110 | + if ( k >= n_lines ) break; |
| 111 | + line += lines[k]; |
| 112 | + if ( j < n_cols - 1 ) { |
| 113 | + line += std::string(col_lens[j]-lines[k].size()+col_spacing,' '); |
| 114 | + } |
| 115 | + } |
| 116 | + MesPrint("%s",line.c_str()); |
| 117 | + } |
| 118 | + return; |
| 119 | + } |
| 120 | + |
| 121 | + // Fallback to a single column. |
| 122 | + |
| 123 | + for ( const auto& f : lines ) { |
| 124 | + MesPrint("%s",f.c_str()); |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +/** |
| 129 | + * Prints the list of available features. |
| 130 | + */ |
| 131 | +void PrintFeatureList(void) |
| 132 | +{ |
| 133 | + std::vector<std::string> feature_list = { |
| 134 | + |
| 135 | +#ifdef ENABLE_BACKTRACE |
| 136 | + "+backtrace", |
| 137 | +#else |
| 138 | + "-backtrace", |
| 139 | +#endif |
| 140 | + |
| 141 | +#ifdef DEBUGGING |
| 142 | + "+debugging", |
| 143 | +#else |
| 144 | + "-debugging", |
| 145 | +#endif |
| 146 | + |
| 147 | +#ifdef WITHFLINT |
| 148 | + "+flint=" + std::string(flint_version), |
| 149 | +#else |
| 150 | + "-flint", |
| 151 | +#endif |
| 152 | + |
| 153 | +#ifdef WITHFLOAT |
| 154 | + "+float", |
| 155 | +#else |
| 156 | + "-float", |
| 157 | +#endif |
| 158 | + |
| 159 | +#ifdef WITHGMP |
| 160 | + "+gmp=" + std::string(gmp_version), |
| 161 | +#else |
| 162 | + "-gmp", |
| 163 | +#endif |
| 164 | + |
| 165 | +#ifdef WITHMPFR |
| 166 | + "+mpfr=" + std::string(mpfr_get_version()), |
| 167 | +#else |
| 168 | + "-mpfr", |
| 169 | +#endif |
| 170 | + |
| 171 | +#ifdef WITHMPI |
| 172 | + "+mpi", |
| 173 | +#else |
| 174 | + "-mpi", |
| 175 | +#endif |
| 176 | + |
| 177 | +#ifdef UNIX |
| 178 | + "+posix", |
| 179 | +#else |
| 180 | + "-posix", |
| 181 | +#endif |
| 182 | + |
| 183 | +#ifdef WITHPTHREADS |
| 184 | + "+pthreads", |
| 185 | +#else |
| 186 | + "-pthreads", |
| 187 | +#endif |
| 188 | + |
| 189 | +#ifdef WINDOWS |
| 190 | + "+windows", |
| 191 | +#else |
| 192 | + "-windows", |
| 193 | +#endif |
| 194 | + |
| 195 | +#ifdef WITHZLIB |
| 196 | + "+zlib=" + std::string(zlibVersion()), |
| 197 | +#else |
| 198 | + "-zlib", |
| 199 | +#endif |
| 200 | + |
| 201 | +#ifdef WITHZSTD |
| 202 | + "+zstd=" + std::string(ZSTD_versionString()), |
| 203 | +#else |
| 204 | + "-zstd", |
| 205 | +#endif |
| 206 | + |
| 207 | + }; |
| 208 | + |
| 209 | + PrintMulticolumn(feature_list); |
| 210 | +} |
| 211 | + |
| 212 | +// #] PrintFeatureList : |
0 commit comments