NeoMutt  2020-11-20
Teaching an old dog new tricks
DOXYGEN
myvar.h File Reference

Handling of personal config ('my' variables) More...

#include "mutt/lib.h"
+ Include dependency graph for myvar.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  MyVar
 A user-set variable. More...
 

Functions

 TAILQ_HEAD (MyVarList, MyVar)
 
void myvar_del (const char *var)
 Unset the value of a "my_" variable. More...
 
const char * myvar_get (const char *var)
 Get the value of a "my_" variable. More...
 
void myvar_set (const char *var, const char *val)
 Set the value of a "my_" variable. More...
 
void myvarlist_free (struct MyVarList *list)
 Free a List of MyVars. More...
 

Variables

struct MyVarList MyVars
 List of all the user's custom config variables. More...
 

Detailed Description

Handling of personal config ('my' variables)

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 myvar.h.

Function Documentation

◆ TAILQ_HEAD()

TAILQ_HEAD ( MyVarList  ,
MyVar   
)

◆ myvar_del()

void myvar_del ( const char *  var)

Unset the value of a "my_" variable.

Parameters
varVariable name

Definition at line 112 of file myvar.c.

113 {
114  struct MyVar *myv = NULL;
115 
116  TAILQ_FOREACH(myv, &MyVars, entries)
117  {
118  if (mutt_str_equal(myv->name, var))
119  {
120  TAILQ_REMOVE(&MyVars, myv, entries);
121  myvar_free(&myv);
122  return;
123  }
124  }
125 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
static void myvar_free(struct MyVar **ptr)
Free a MyVar.
Definition: myvar.c:56
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
char * name
Name of user variable.
Definition: myvar.h:33
A user-set variable.
Definition: myvar.h:31
struct MyVarList MyVars
List of all the user's custom config variables.
Definition: myvar.c:34
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:834
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ myvar_get()

const char* myvar_get ( const char *  var)

Get the value of a "my_" variable.

Parameters
varVariable name
Return values
ptrSuccess, value of variable
NULLError, variable doesn't exist

Definition at line 73 of file myvar.c.

74 {
75  struct MyVar *myv = NULL;
76 
77  TAILQ_FOREACH(myv, &MyVars, entries)
78  {
79  if (mutt_str_equal(myv->name, var))
80  return NONULL(myv->value);
81  }
82 
83  return NULL;
84 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
#define NONULL(x)
Definition: string2.h:37
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
char * name
Name of user variable.
Definition: myvar.h:33
A user-set variable.
Definition: myvar.h:31
struct MyVarList MyVars
List of all the user's custom config variables.
Definition: myvar.c:34
char * value
Value of user variable.
Definition: myvar.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ myvar_set()

void myvar_set ( const char *  var,
const char *  val 
)

Set the value of a "my_" variable.

Parameters
varVariable name
valValue to set

Definition at line 91 of file myvar.c.

92 {
93  struct MyVar *myv = NULL;
94 
95  TAILQ_FOREACH(myv, &MyVars, entries)
96  {
97  if (mutt_str_equal(myv->name, var))
98  {
99  mutt_str_replace(&myv->value, val);
100  return;
101  }
102  }
103 
104  myv = myvar_new(var, val);
105  TAILQ_INSERT_TAIL(&MyVars, myv, entries);
106 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
static struct MyVar * myvar_new(const char *name, const char *value)
Create a new MyVar.
Definition: myvar.c:44
char * name
Name of user variable.
Definition: myvar.h:33
A user-set variable.
Definition: myvar.h:31
struct MyVarList MyVars
List of all the user's custom config variables.
Definition: myvar.c:34
char * value
Value of user variable.
Definition: myvar.h:34
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:802
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:446
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ myvarlist_free()

void myvarlist_free ( struct MyVarList *  list)

Free a List of MyVars.

Parameters
listList of MyVars

Definition at line 131 of file myvar.c.

132 {
133  if (!list)
134  return;
135 
136  struct MyVar *myv = NULL;
137  struct MyVar *tmp = NULL;
138  TAILQ_FOREACH_SAFE(myv, list, entries, tmp)
139  {
140  TAILQ_REMOVE(list, myv, entries);
141  myvar_free(&myv);
142  }
143 }
static void myvar_free(struct MyVar **ptr)
Free a MyVar.
Definition: myvar.c:56
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:728
A user-set variable.
Definition: myvar.h:31
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:834
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ MyVars

struct MyVarList MyVars

List of all the user's custom config variables.

Definition at line 34 of file myvar.c.