NeoMutt  2025-01-09-144-gb44c67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
version.h File Reference

Display version and copyright about NeoMutt. More...

#include <stdbool.h>
#include <stdio.h>
#include "mutt/lib.h"
+ Include dependency graph for version.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  KeyValue
 Key/Value pairs. More...
 
struct  CompileOption
 Built-in capability. More...
 
struct  NeoMuttVersion
 Version info about NeoMutt. More...
 

Functions

 ARRAY_HEAD (KeyValueArray, struct KeyValue)
 
struct NeoMuttVersionversion_get (void)
 Get NeoMutt version info.
 
void version_free (struct NeoMuttVersion **ptr)
 Free a NeoMuttVersion.
 
const char * mutt_make_version (void)
 Generate the NeoMutt version string.
 
bool print_version (FILE *fp, bool use_ansi)
 Print system and compile info to a file.
 
bool print_copyright (void)
 Print copyright message.
 
bool feature_enabled (const char *name)
 Test if a compile-time feature is enabled.
 

Detailed Description

Display version and copyright about NeoMutt.

Authors
  • Richard Russon

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file version.h.

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( KeyValueArray  ,
struct KeyValue   
)

◆ version_get()

struct NeoMuttVersion * version_get ( void  )

Get NeoMutt version info.

Return values
ptrNeoMuttVersion

Definition at line 469 of file version.c.

470{
471 struct NeoMuttVersion *ver = MUTT_MEM_CALLOC(1, struct NeoMuttVersion);
472
474
475 ARRAY_INIT(&ver->system);
476 system_get(&ver->system);
477
478#ifdef USE_HCACHE
480#ifdef USE_HCACHE_COMPRESSION
481 ver->compression = compress_list();
482#endif
483#endif
484
487
488 rstrip_in_place((char *) cc_cflags);
490
491 ver->feature = CompOpts;
492
493 if (DevelOpts[0].name)
494 ver->devel = DevelOpts;
495
496 ARRAY_INIT(&ver->paths);
497 paths_get(&ver->paths);
498
499 return ver;
500}
#define ARRAY_INIT(head)
Initialize an array.
Definition: array.h:65
struct Slist * compress_list(void)
Get a list of compression backend names.
Definition: compress.c:59
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
struct Slist * slist_parse(const char *str, uint32_t flags)
Parse a list of strings into a list.
Definition: slist.c:177
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:254
struct Slist * store_backend_list(void)
Get a list of backend names.
Definition: store.c:85
Version info about NeoMutt.
Definition: version.h:53
struct KeyValueArray paths
Compiled-in paths.
Definition: version.h:67
struct Slist * configure
Configure options.
Definition: version.h:61
const char * version
Version of NeoMutt: YYYYMMDD-NUM-HASH (number of commits, git hash)
Definition: version.h:54
struct Slist * compression
Compression methods, e.g. zlib.
Definition: version.h:59
struct Slist * storage
Storage backends, e.g. lmdb.
Definition: version.h:58
const struct CompileOption * devel
Compiled-in development features.
Definition: version.h:65
const struct CompileOption * feature
Compiled-in features.
Definition: version.h:64
struct Slist * compilation
Compilation CFLAGS.
Definition: version.h:62
struct KeyValueArray system
System information.
Definition: version.h:56
#define D_SLIST_SEP_SPACE
Slist items are space-separated.
Definition: types.h:109
static const struct CompileOption DevelOpts[]
Devel options strings for neomutt -v output.
Definition: version.c:249
static void paths_get(struct KeyValueArray *kva)
Get compiled-in paths.
Definition: version.c:414
const char * mutt_make_version(void)
Generate the NeoMutt version string.
Definition: version.c:295
unsigned char configure_options[]
static void system_get(struct KeyValueArray *kva)
Get info about system libraries.
Definition: version.c:327
unsigned char cc_cflags[]
static char * rstrip_in_place(char *s)
Strip a trailing carriage return.
Definition: version.c:309
static const struct CompileOption CompOpts[]
Compile options strings for neomutt -v output.
Definition: version.c:118
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ version_free()

void version_free ( struct NeoMuttVersion **  ptr)

Free a NeoMuttVersion.

Parameters
ptrNeoMuttVersion to free

Definition at line 506 of file version.c.

507{
508 if (!ptr || !*ptr)
509 return;
510
511 struct NeoMuttVersion *ver = *ptr;
512
513 FREE(&ver->version);
514
515 kva_clear(&ver->system);
516 kva_clear(&ver->paths);
517
518 slist_free(&ver->storage);
519 slist_free(&ver->compression);
520 slist_free(&ver->configure);
521 slist_free(&ver->compilation);
522
523 FREE(ptr);
524}
#define FREE(x)
Definition: memory.h:55
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition: slist.c:124
static void kva_clear(struct KeyValueArray *kva)
Free the strings of a KeyValueArray.
Definition: version.c:452
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_make_version()

const char * mutt_make_version ( void  )

Generate the NeoMutt version string.

Return values
ptrVersion string
Note
This returns a pointer to a static buffer

Definition at line 295 of file version.c.

296{
297 static char vstring[256];
298 snprintf(vstring, sizeof(vstring), "NeoMutt %s%s", PACKAGE_VERSION, GitVer);
299 return vstring;
300}
const char * GitVer
+ Here is the caller graph for this function:

◆ print_version()

bool print_version ( FILE *  fp,
bool  use_ansi 
)

Print system and compile info to a file.

Parameters
fpFile to print to
use_ansiUse ANSI colour escape sequences
Return values
trueText displayed

Print information about the current system NeoMutt is running on. Also print a list of all the compile-time information.

Definition at line 591 of file version.c.

592{
593 if (!fp)
594 return false;
595
596 struct KeyValue *kv = NULL;
597 struct ListNode *np = NULL;
598 struct NeoMuttVersion *ver = version_get();
599
600 const char *col_cyan = "";
601 const char *col_bold = "";
602 const char *col_end = "";
603
604 if (use_ansi)
605 {
606 col_cyan = "\033[1;36m"; // Escape, cyan
607 col_bold = "\033[1m"; // Escape, bold
608 col_end = "\033[0m"; // Escape, end
609 }
610
611 fprintf(fp, "%s%s%s\n", col_cyan, ver->version, col_end);
612 fprintf(fp, "%s\n", _(Notice));
613
614 ARRAY_FOREACH(kv, &ver->system)
615 {
616 fprintf(fp, "%s%s:%s %s\n", col_bold, kv->key, col_end, kv->value);
617 }
618
619 if (ver->storage)
620 {
621 fprintf(fp, "%sstorage:%s ", col_bold, col_end);
622 STAILQ_FOREACH(np, &ver->storage->head, entries)
623 {
624 fputs(np->data, fp);
625 if (STAILQ_NEXT(np, entries))
626 fputs(", ", fp);
627 }
628 fputs("\n", fp);
629 }
630
631 if (ver->compression)
632 {
633 fprintf(fp, "%scompression:%s ", col_bold, col_end);
634 STAILQ_FOREACH(np, &ver->compression->head, entries)
635 {
636 fputs(np->data, fp);
637 if (STAILQ_NEXT(np, entries))
638 fputs(", ", fp);
639 }
640 fputs("\n", fp);
641 }
642 fputs("\n", fp);
643
644 fprintf(fp, "%sConfigure options:%s ", col_bold, col_end);
645 if (ver->configure)
646 {
647 STAILQ_FOREACH(np, &ver->configure->head, entries)
648 {
649 if (!np || !np->data)
650 continue;
651 fputs(np->data, fp);
652 if (STAILQ_NEXT(np, entries))
653 fputs(" ", fp);
654 }
655 }
656 fputs("\n\n", fp);
657
658 if (ver->compilation)
659 {
660 fprintf(fp, "%sCompilation CFLAGS:%s ", col_bold, col_end);
661 STAILQ_FOREACH(np, &ver->compilation->head, entries)
662 {
663 if (!np || !np->data)
664 continue;
665 fputs(np->data, fp);
666 if (STAILQ_NEXT(np, entries))
667 fputs(" ", fp);
668 }
669 fputs("\n\n", fp);
670 }
671
672 fprintf(fp, "%s%s%s\n", col_bold, _("Compile options:"), col_end);
673 print_compile_options(ver->feature, fp, use_ansi);
674 fputs("\n", fp);
675
676 if (ver->devel)
677 {
678 fprintf(fp, "%s%s%s\n", col_bold, _("Devel options:"), col_end);
679 print_compile_options(ver->devel, fp, use_ansi);
680 fputs("\n", fp);
681 }
682
683 ARRAY_FOREACH(kv, &ver->paths)
684 {
685 fprintf(fp, "%s%s%s=\"%s\"\n", col_bold, kv->key, col_end, kv->value);
686 }
687 fputs("\n", fp);
688
689 fputs(_(ReachingUs), fp);
690
691 version_free(&ver);
692 return true;
693}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:214
#define _(a)
Definition: message.h:28
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:390
#define STAILQ_NEXT(elm, field)
Definition: queue.h:439
Key/Value pairs.
Definition: version.h:34
const char * key
Definition: version.h:35
const char * value
Definition: version.h:36
A List node for strings.
Definition: list.h:37
char * data
String.
Definition: list.h:38
struct ListHead head
List containing values.
Definition: slist.h:38
void version_free(struct NeoMuttVersion **ptr)
Free a NeoMuttVersion.
Definition: version.c:506
static const char * ReachingUs
CLI Version: How to reach the NeoMutt Team.
Definition: version.c:102
static const char * Notice
CLI Version: Warranty notice.
Definition: version.c:109
struct NeoMuttVersion * version_get(void)
Get NeoMutt version info.
Definition: version.c:469
static void print_compile_options(const struct CompileOption *co, FILE *fp, bool use_ansi)
Print a list of enabled/disabled features.
Definition: version.c:539
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_copyright()

bool print_copyright ( void  )

Print copyright message.

Return values
trueText displayed

Print the authors' copyright messages, the GPL license and some contact information for the NeoMutt project.

Definition at line 702 of file version.c.

703{
704 puts(mutt_make_version());
705 puts(Copyright);
706 puts(_(Thanks));
707 puts(_(License));
708 puts(_(ReachingUs));
709
710 fflush(stdout);
711 return !ferror(stdout);
712}
static const char * Thanks
CLI Version: Thanks.
Definition: version.c:82
static const char * License
CLI Version: License.
Definition: version.c:86
static const char * Copyright
CLI Version: Authors' copyrights.
Definition: version.c:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ feature_enabled()

bool feature_enabled ( const char *  name)

Test if a compile-time feature is enabled.

Parameters
nameCompile-time symbol of the feature
Return values
trueFeature enabled
falseFeature not enabled, or not compiled in

Many of the larger features of neomutt can be disabled at compile time. They define a symbol and use ifdef's around their code. The symbols are mirrored in "CompileOption CompOpts[]" in this file.

This function checks if one of these symbols is present in the code.

These symbols are also seen in the output of "neomutt -v".

Definition at line 729 of file version.c.

730{
731 if (!name)
732 return false;
733 for (int i = 0; CompOpts[i].name; i++)
734 {
735 if (mutt_str_equal(name, CompOpts[i].name))
736 {
737 return CompOpts[i].enabled;
738 }
739 }
740 return false;
741}
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:661
const char * name
Option name.
Definition: version.h:45
int enabled
0 Disabled, 1 Enabled, 2 Devel only
Definition: version.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function: