NeoMutt  2018-07-16 +1783-b00bd9
Teaching an old dog new tricks
DOXYGEN
myvar.c File Reference

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

#include "config.h"
#include <stddef.h>
#include "mutt/mutt.h"
#include "myvar.h"
+ Include dependency graph for myvar.c:

Go to the source code of this file.

Functions

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 myvar_del (const char *var)
 Unset the value of a "my_" variable. More...
 

Variables

struct MyVarHead MyVars = TAILQ_HEAD_INITIALIZER(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.c.

Function Documentation

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 42 of file myvar.c.

43 {
44  struct MyVar *myv = NULL;
45 
46  TAILQ_FOREACH(myv, &MyVars, entries)
47  {
48  if (mutt_str_strcmp(myv->name, var) == 0)
49  return NONULL(myv->value);
50  }
51 
52  return NULL;
53 }
#define NONULL(x)
Definition: string2.h:36
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
char * name
Definition: myvar.h:33
A user-set variable.
Definition: myvar.h:31
char * value
Definition: myvar.h:34
struct MyVarHead MyVars
List of all the user&#39;s custom config variables.
Definition: myvar.c:34
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:618

+ Here is the caller graph for this function:

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 60 of file myvar.c.

61 {
62  struct MyVar *myv = NULL;
63 
64  TAILQ_FOREACH(myv, &MyVars, entries)
65  {
66  if (mutt_str_strcmp(myv->name, var) == 0)
67  {
68  mutt_str_replace(&myv->value, val);
69  return;
70  }
71  }
72 
73  myv = mutt_mem_calloc(1, sizeof(struct MyVar));
74  myv->name = mutt_str_strdup(var);
75  myv->value = mutt_str_strdup(val);
76  TAILQ_INSERT_TAIL(&MyVars, myv, entries);
77 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
char * name
Definition: myvar.h:33
A user-set variable.
Definition: myvar.h:31
char * value
Definition: myvar.h:34
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:803
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:456
struct MyVarHead MyVars
List of all the user&#39;s custom config variables.
Definition: myvar.c:34
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:618

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void myvar_del ( const char *  var)

Unset the value of a "my_" variable.

Parameters
varVariable name

Definition at line 83 of file myvar.c.

84 {
85  struct MyVar *myv = NULL;
86 
87  TAILQ_FOREACH(myv, &MyVars, entries)
88  {
89  if (mutt_str_strcmp(myv->name, var) == 0)
90  {
91  TAILQ_REMOVE(&MyVars, myv, entries);
92  FREE(&myv->name);
93  FREE(&myv->value);
94  FREE(&myv);
95  return;
96  }
97  }
98 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
char * name
Definition: myvar.h:33
A user-set variable.
Definition: myvar.h:31
char * value
Definition: myvar.h:34
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:821
struct MyVarHead MyVars
List of all the user&#39;s custom config variables.
Definition: myvar.c:34
#define FREE(x)
Definition: memory.h:40
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:618

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

struct MyVarHead MyVars = TAILQ_HEAD_INITIALIZER(MyVars)

List of all the user's custom config variables.

Definition at line 34 of file myvar.c.