summaryrefslogtreecommitdiff
path: root/src/bin/psql/variables.h
blob: 4f01fe81293893d5fd7ef882d60738d465e78fbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * psql - the PostgreSQL interactive terminal
 *
 * Copyright (c) 2000-2010, PostgreSQL Global Development Group
 *
 * src/bin/psql/variables.h
 */
#ifndef VARIABLES_H
#define VARIABLES_H

/*
 * This implements a sort of variable repository. One could also think of it
 * as a cheap version of an associative array. In each one of these
 * datastructures you can store name/value pairs.  There can also be an
 * "assign hook" function that is called whenever the variable's value is
 * changed.
 *
 * An "unset" operation causes the hook to be called with newval == NULL.
 *
 * Note: if value == NULL then the variable is logically unset, but we are
 * keeping the struct around so as not to forget about its hook function.
 */
typedef void (*VariableAssignHook) (const char *newval);

struct _variable
{
	char	   *name;
	char	   *value;
	VariableAssignHook assign_hook;
	struct _variable *next;
};

typedef struct _variable *VariableSpace;

/* Allowed chars in a variable's name */
#define VALID_VARIABLE_CHARS "abcdefghijklmnopqrstuvwxyz"\
							 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789_"

VariableSpace CreateVariableSpace(void);
const char *GetVariable(VariableSpace space, const char *name);

bool		ParseVariableBool(const char *val);
int ParseVariableNum(const char *val,
				 int defaultval,
				 int faultval,
				 bool allowtrail);
int GetVariableNum(VariableSpace space,
			   const char *name,
			   int defaultval,
			   int faultval,
			   bool allowtrail);

void		PrintVariables(VariableSpace space);

bool		SetVariable(VariableSpace space, const char *name, const char *value);
bool		SetVariableAssignHook(VariableSpace space, const char *name, VariableAssignHook hook);
bool		SetVariableBool(VariableSpace space, const char *name);
bool		DeleteVariable(VariableSpace space, const char *name);

#endif   /* VARIABLES_H */