Skip to content

Commit

Permalink
global: make more vars const
Browse files Browse the repository at this point in the history
Make lots more global variables const.
  • Loading branch information
flatcap committed Apr 28, 2023
1 parent 353df76 commit 34106a6
Show file tree
Hide file tree
Showing 29 changed files with 44 additions and 46 deletions.
2 changes: 1 addition & 1 deletion compmbox/compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ static int comp_path_parent(char *buf, size_t buflen)
* Compress only uses open, close and check.
* The message functions are delegated to mbox.
*/
struct MxOps MxCompOps = {
const struct MxOps MxCompOps = {
// clang-format off
.type = MUTT_COMPRESSED,
.name = "compressed",
Expand Down
2 changes: 1 addition & 1 deletion compmbox/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ bool mutt_comp_can_append(struct Mailbox *m);
bool mutt_comp_can_read(const char *path);
int mutt_comp_valid_command(const char *cmd);

extern struct MxOps MxCompOps;
extern const struct MxOps MxCompOps;

#endif /* MUTT_COMPMBOX_LIB_H */
2 changes: 1 addition & 1 deletion imap/imap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2514,7 +2514,7 @@ static int imap_path_is_empty(const char *path)
/**
* MxImapOps - IMAP Mailbox - Implements ::MxOps - @ingroup mx_api
*/
struct MxOps MxImapOps = {
const struct MxOps MxImapOps = {
// clang-format off
.type = MUTT_IMAP,
.name = "imap",
Expand Down
2 changes: 1 addition & 1 deletion imap/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ enum MailboxType imap_path_probe(const char *path, const struct stat *st);
int imap_path_canon(char *buf, size_t buflen);
void imap_notify_delete_email(struct Mailbox *m, struct Email *e);

extern struct MxOps MxImapOps;
extern const struct MxOps MxImapOps;

/* browse.c */
int imap_browse(const char *path, struct BrowserState *state);
Expand Down
4 changes: 2 additions & 2 deletions maildir/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
struct Email;
struct HeaderCache;

extern struct MxOps MxMaildirOps;
extern struct MxOps MxMhOps;
extern const struct MxOps MxMaildirOps;
extern const struct MxOps MxMhOps;

int maildir_check_empty (const char *path);
void maildir_gen_flags (char *dest, size_t destlen, struct Email *e);
Expand Down
2 changes: 1 addition & 1 deletion maildir/maildir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ static enum MailboxType maildir_path_probe(const char *path, const struct stat *
/**
* MxMaildirOps - Maildir Mailbox - Implements ::MxOps - @ingroup mx_api
*/
struct MxOps MxMaildirOps = {
const struct MxOps MxMaildirOps = {
// clang-format off
.type = MUTT_MAILDIR,
.name = "maildir",
Expand Down
2 changes: 1 addition & 1 deletion maildir/mh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ static enum MailboxType mh_path_probe(const char *path, const struct stat *st)
/**
* MxMhOps - MH Mailbox - Implements ::MxOps - @ingroup mx_api
*/
struct MxOps MxMhOps = {
const struct MxOps MxMhOps = {
// clang-format off
.type = MUTT_MH,
.name = "mh",
Expand Down
4 changes: 2 additions & 2 deletions mbox/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ struct MboxAccountData
bool append : 1; ///< mailbox is opened in append mode
};

extern struct MxOps MxMboxOps;
extern struct MxOps MxMmdfOps;
extern const struct MxOps MxMboxOps;
extern const struct MxOps MxMmdfOps;

#define MMDF_SEP "\001\001\001\001\n"

Expand Down
4 changes: 2 additions & 2 deletions mbox/mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,7 @@ static enum MxStatus mbox_mbox_check_stats(struct Mailbox *m, uint8_t flags)
/**
* MxMboxOps - Mbox Mailbox - Implements ::MxOps - @ingroup mx_api
*/
struct MxOps MxMboxOps = {
const struct MxOps MxMboxOps = {
// clang-format off
.type = MUTT_MBOX,
.name = "mbox",
Expand Down Expand Up @@ -1885,7 +1885,7 @@ struct MxOps MxMboxOps = {
/**
* MxMmdfOps - MMDF Mailbox - Implements ::MxOps - @ingroup mx_api
*/
struct MxOps MxMmdfOps = {
const struct MxOps MxMmdfOps = {
// clang-format off
.type = MUTT_MMDF,
.name = "mmdf",
Expand Down
2 changes: 1 addition & 1 deletion mutt/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

/// Lookup table for NotifyType
/// Must be the same size and order as #NotifyType
static char *NotifyTypeNames[] = {
static const char *NotifyTypeNames[] = {
"NT_ALL", "NT_ACCOUNT", "NT_ALIAS", "NT_ALTERN", "NT_ATTACH",
"NT_BINDING", "NT_COLOR", "NT_COMMAND", "NT_CONFIG", "NT_CONTEXT",
"NT_EMAIL", "NT_ENVELOPE", "NT_GLOBAL", "NT_HEADER", "NT_INDEX",
Expand Down
4 changes: 2 additions & 2 deletions mutt/pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ static size_t BufferPoolCount = 0;
/// Total size of the pool
static size_t BufferPoolLen = 0;
/// Amount to increase the size of the pool
static size_t BufferPoolIncrement = 20;
static const size_t BufferPoolIncrement = 20;
/// Minimum size for a buffer
static size_t BufferPoolInitialBufferSize = 1024;
static const size_t BufferPoolInitialBufferSize = 1024;
/// A pool of buffers
static struct Buffer **BufferPool = NULL;

Expand Down
2 changes: 1 addition & 1 deletion mutt_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static const struct Mapping UseThreadsMethods[] = {
};

/// Data for the $use_threads enumeration
struct EnumDef UseThreadsTypeDef = {
const struct EnumDef UseThreadsTypeDef = {
"use_threads_type",
4,
(struct Mapping *) &UseThreadsMethods,
Expand Down
2 changes: 1 addition & 1 deletion mutt_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ enum UseThreads
UT_REVERSE, ///< Reverse threading (subthreads above root)
};

extern struct EnumDef UseThreadsTypeDef;
extern const struct EnumDef UseThreadsTypeDef;

int mutt_traverse_thread(struct Email *e, MuttThreadFlags flag);
#define mutt_collapse_thread(e) mutt_traverse_thread(e, MUTT_THREAD_COLLAPSE)
Expand Down
2 changes: 1 addition & 1 deletion mx.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static const struct Mapping MboxTypeMap[] = {
};

/// Data for the $mbox_type enumeration
struct EnumDef MboxTypeDef = {
const struct EnumDef MboxTypeDef = {
"mbox_type",
4,
(struct Mapping *) &MboxTypeMap,
Expand Down
4 changes: 1 addition & 3 deletions mx.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
struct Buffer;
struct Email;

extern const struct MxOps *mx_ops[];

extern struct EnumDef MboxTypeDef;
extern const struct EnumDef MboxTypeDef;

typedef uint8_t MsgOpenFlags; ///< Flags for mx_msg_open_new(), e.g. #MUTT_ADD_FROM
#define MUTT_MSG_NO_FLAGS 0 ///< No flags are set
Expand Down
10 changes: 5 additions & 5 deletions ncrypt/crypt_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
*/
struct CryptModule
{
struct CryptModuleSpecs *specs; ///< Crypto module definition
STAILQ_ENTRY(CryptModule) entries; ///< Linked list
const struct CryptModuleSpecs *specs; ///< Crypto module definition
STAILQ_ENTRY(CryptModule) entries; ///< Linked list
};
STAILQ_HEAD(CryptModuleList, CryptModule);

Expand All @@ -49,7 +49,7 @@ static struct CryptModuleList CryptModules = STAILQ_HEAD_INITIALIZER(CryptModule
* crypto_module_register - Register a new crypto module
* @param specs API functions
*/
void crypto_module_register(struct CryptModuleSpecs *specs)
void crypto_module_register(const struct CryptModuleSpecs *specs)
{
struct CryptModule *module = mutt_mem_calloc(1, sizeof(struct CryptModule));
module->specs = specs;
Expand All @@ -63,9 +63,9 @@ void crypto_module_register(struct CryptModuleSpecs *specs)
*
* This function is usually used via the CRYPT_MOD_CALL[_CHECK] macros.
*/
struct CryptModuleSpecs *crypto_module_lookup(int identifier)
const struct CryptModuleSpecs *crypto_module_lookup(int identifier)
{
struct CryptModule *module = NULL;
const struct CryptModule *module = NULL;
STAILQ_FOREACH(module, &CryptModules, entries)
{
if (module->specs->identifier == identifier)
Expand Down
4 changes: 2 additions & 2 deletions ncrypt/crypt_mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ struct CryptModuleSpecs
};

/* High Level crypto module interface */
void crypto_module_register(struct CryptModuleSpecs *specs);
struct CryptModuleSpecs *crypto_module_lookup(int identifier);
void crypto_module_register(const struct CryptModuleSpecs *specs);
const struct CryptModuleSpecs *crypto_module_lookup(int identifier);

#endif /* MUTT_NCRYPT_CRYPT_MOD_H */
2 changes: 1 addition & 1 deletion ncrypt/crypt_mod_pgp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/**
* CryptModPgpClassic - CLI PGP - Implements ::CryptModuleSpecs
*/
struct CryptModuleSpecs CryptModPgpClassic = {
const struct CryptModuleSpecs CryptModPgpClassic = {
// clang-format off
APPLICATION_PGP,

Expand Down
2 changes: 1 addition & 1 deletion ncrypt/crypt_mod_pgp_gpgme.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static bool pgp_gpgme_valid_passphrase(void)
/**
* CryptModPgpGpgme - GPGME PGP - Implements ::CryptModuleSpecs
*/
struct CryptModuleSpecs CryptModPgpGpgme = {
const struct CryptModuleSpecs CryptModPgpGpgme = {
// clang-format off
APPLICATION_PGP,

Expand Down
2 changes: 1 addition & 1 deletion ncrypt/crypt_mod_smime_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void smime_class_cleanup(void)
/**
* CryptModSmimeClassic - CLI SMIME - Implements ::CryptModuleSpecs
*/
struct CryptModuleSpecs CryptModSmimeClassic = {
const struct CryptModuleSpecs CryptModSmimeClassic = {
// clang-format off
APPLICATION_SMIME,

Expand Down
2 changes: 1 addition & 1 deletion ncrypt/crypt_mod_smime_gpgme.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static bool smime_gpgme_valid_passphrase(void)
/**
* CryptModSmimeGpgme - GPGME SMIME - Implements ::CryptModuleSpecs
*/
struct CryptModuleSpecs CryptModSmimeGpgme = {
const struct CryptModuleSpecs CryptModSmimeGpgme = {
// clang-format off
APPLICATION_SMIME,

Expand Down
8 changes: 4 additions & 4 deletions ncrypt/cryptglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ struct Address;
struct AddressList;

#ifdef CRYPT_BACKEND_CLASSIC_PGP
extern struct CryptModuleSpecs CryptModPgpClassic;
extern const struct CryptModuleSpecs CryptModPgpClassic;
#endif

#ifdef CRYPT_BACKEND_CLASSIC_SMIME
extern struct CryptModuleSpecs CryptModSmimeClassic;
extern const struct CryptModuleSpecs CryptModSmimeClassic;
#endif

#ifdef CRYPT_BACKEND_GPGME
extern struct CryptModuleSpecs CryptModPgpGpgme;
extern struct CryptModuleSpecs CryptModSmimeGpgme;
extern const struct CryptModuleSpecs CryptModPgpGpgme;
extern const struct CryptModuleSpecs CryptModSmimeGpgme;
#endif

/* If the crypto module identifier by IDENTIFIER has been registered,
Expand Down
2 changes: 1 addition & 1 deletion nntp/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct NntpAccountData;
struct stat;

extern struct NntpAccountData *CurrentNewsSrv; ///< Current NNTP news server
extern struct MxOps MxNntpOps;
extern const struct MxOps MxNntpOps;

/* article number type and format */
#define anum_t long
Expand Down
2 changes: 1 addition & 1 deletion nntp/nntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2772,7 +2772,7 @@ static int nntp_path_parent(char *buf, size_t buflen)
/**
* MxNntpOps - NNTP Mailbox - Implements ::MxOps - @ingroup mx_api
*/
struct MxOps MxNntpOps = {
const struct MxOps MxNntpOps = {
// clang-format off
.type = MUTT_NNTP,
.name = "nntp",
Expand Down
2 changes: 1 addition & 1 deletion notmuch/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
struct Email;
struct stat;

extern struct MxOps MxNotmuchOps;
extern const struct MxOps MxNotmuchOps;

void nm_init (void);
void nm_db_debug_check (struct Mailbox *m);
Expand Down
2 changes: 1 addition & 1 deletion notmuch/notmuch.c
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,7 @@ static int nm_path_parent(char *buf, size_t buflen)
/**
* MxNotmuchOps - Notmuch Mailbox - Implements ::MxOps - @ingroup mx_api
*/
struct MxOps MxNotmuchOps = {
const struct MxOps MxNotmuchOps = {
// clang-format off
.type = MUTT_NOTMUCH,
.name = "notmuch",
Expand Down
2 changes: 1 addition & 1 deletion pop/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

struct stat;

extern struct MxOps MxPopOps;
extern const struct MxOps MxPopOps;

void pop_fetch_mail(void);
enum MailboxType pop_path_probe(const char *path, const struct stat *st);
Expand Down
2 changes: 1 addition & 1 deletion pop/pop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ static int pop_path_parent(char *buf, size_t buflen)
/**
* MxPopOps - POP Mailbox - Implements ::MxOps - @ingroup mx_api
*/
struct MxOps MxPopOps = {
const struct MxOps MxPopOps = {
// clang-format off
.type = MUTT_POP,
.name = "pop",
Expand Down
8 changes: 4 additions & 4 deletions version.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct CompileOptions
/* These are sorted by the display string */

/// Default options strings for `neomutt -v` output
static struct CompileOptions CompOptsDefault[] = {
static const struct CompileOptions CompOptsDefault[] = {
{ "attach_headers_color", 1 },
{ "compose_to_sender", 1 },
{ "compress", 1 },
Expand Down Expand Up @@ -165,7 +165,7 @@ static struct CompileOptions CompOptsDefault[] = {
};

/// Compile options strings for `neomutt -v` output
static struct CompileOptions CompOpts[] = {
static const struct CompileOptions CompOpts[] = {
#ifdef USE_AUTOCRYPT
{ "autocrypt", 1 },
#else
Expand Down Expand Up @@ -301,7 +301,7 @@ static struct CompileOptions CompOpts[] = {
};

/// Debug options strings for `neomutt -v` output
static struct CompileOptions DebugOpts[] = {
static const struct CompileOptions DebugOpts[] = {
#ifdef USE_ASAN
{ "asan", 2 },
#endif
Expand Down Expand Up @@ -345,7 +345,7 @@ static struct CompileOptions DebugOpts[] = {
* The output is of the form: "+enabled_feature -disabled_feature" and is
* wrapped to SCREEN_WIDTH characters.
*/
static void print_compile_options(struct CompileOptions *co, FILE *fp)
static void print_compile_options(const struct CompileOptions *co, FILE *fp)
{
if (!co || !fp)
return;
Expand Down

0 comments on commit 34106a6

Please sign in to comment.