Skip to content

Commit 42190ad

Browse files
committed
feat: add -vv option to list features (#645)
1 parent eb24708 commit 42190ad

File tree

6 files changed

+235
-8
lines changed

6 files changed

+235
-8
lines changed

doc/form.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ the program.
9696
.BR "-v"
9797
Only the version will be printed. The program terminates immediately after it.
9898
.TP
99+
.BR "-vv"
100+
The same as \fB-v\fR, but additionally prints a list indicating which features are supported.
101+
.TP
99102
.BR "-w"
100103
This should be followed immediately by a number without any space. The number
101104
indicates the number of worker threads for \fBtform\fR. All other versions of

doc/manual/startup.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ \chapter{Running FORM}
6262
information see the "On TotalSize;" statement~\ref{ontotalsize}.
6363
\item[-v] Only the version will be printed. The program terminates
6464
immediately after it.
65+
\item[-vv] The same as -v, but additionally prints a list indicating
66+
which features are supported.
6567
\item[-w] This should be followed immediately by a number. The
6668
number indicates the number of worker threads for \TFORM\@. All other
6769
versions of \FORM\ ignore this parameter. It should be noted that \TFORM\

sources/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SRCBASE = \
1515
execute.c \
1616
extcmd.c \
1717
factor.c \
18+
features.cc \
1819
findpat.c \
1920
form3.h \
2021
fsizes.h \

sources/declare.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ extern int Product(UWORD *,WORD *,WORD);
671671
extern void PrtLong(UWORD *,WORD,UBYTE *);
672672
extern void PrtTerms(void);
673673
extern void PrintDeprecation(const char *,const char *);
674+
extern void PrintFeatureList(void);
674675
extern void PrintRunningTime(void);
675676
extern LONG GetRunningTime(void);
676677
extern int PutBracket(PHEAD WORD *);

sources/features.cc

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
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 :

sources/startup.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,12 @@
109109
/**
110110
* Prints the header line of the output.
111111
*
112-
* @param with_full_info True for printing also runtime information.
112+
* @param par Controls the output mode
113+
* (0: default,
114+
* 1: including runtime information,
115+
* 2: including the feature list).
113116
*/
114-
static void PrintHeader(int with_full_info)
117+
static void PrintHeader(int par)
115118
{
116119
#ifdef WITHMPI
117120
if ( PF.me == MASTER && !AM.silent ) {
@@ -147,7 +150,7 @@ static void PrintHeader(int with_full_info)
147150
s += snprintf(s,250-(s-buffer1)," %d-bits",(WORD)(sizeof(WORD)*16));
148151
*s = 0;
149152
*/
150-
if ( with_full_info ) {
153+
if ( par == 1 ) {
151154
#if defined(WITHPTHREADS) || defined(WITHMPI)
152155
#if defined(WITHPTHREADS)
153156
int nworkers = AM.totalnumberofthreads-1;
@@ -200,6 +203,10 @@ static void PrintHeader(int with_full_info)
200203
MesPrint("%s",buffer1);
201204
AC.LineLength = oldLineLength;
202205
}
206+
207+
if ( par == 2 ) {
208+
PrintFeatureList();
209+
}
203210
}
204211
#ifdef WINDOWS
205212
PrintDeprecation("the native Windows version", "issues/623");
@@ -414,12 +421,13 @@ int DoTail(int argc, UBYTE **argv)
414421
break;
415422
case 'T': /* Print the total size used at end of job */
416423
AM.PrintTotalSize = 1; break;
417-
case 'v':
424+
case 'v': /* Print version information */
425+
if ( s[1] == 'v' ) {
426+
PrintHeader(2);
427+
return(1);
428+
}
418429
printversion:;
419-
#ifdef WITHMPI
420-
if ( PF.me == MASTER )
421-
#endif
422-
PrintHeader(0);
430+
PrintHeader(0);
423431
if ( onlyversion ) return(1);
424432
goto NoFile;
425433
case 'y': /* Preprocessor dumps output. No compilation. */

0 commit comments

Comments
 (0)